POE::Wheel::ListenAccept - accept connections from regular listening sockets |
POE::Wheel::ListenAccept - accept connections from regular listening sockets
$wheel = POE::Wheel::ListenAccept->new( Handle => $socket_handle, # Listening socket AcceptEvent => $accept_event_name, # Event to emit on successful accept ErrorEvent => $error_event_name, # Event to emit on some kind of error );
$wheel->event( AcceptEvent => $new_event_name ); # Add/change event $wheel->event( ErrorEvent => undef ); # Remove event
ListenAccept listens on an already established socket and accepts
remote connections from it as they arrive. Sockets it listens on can
come from anything that makes filehandles. This includes socket()
calls and IO::Socket::* instances.
The ListenAccept wheel generates events for successful and failed connections. EAGAIN is handled internally, so sessions needn't worry about it.
This wheel neither needs nor includes a put()
method.
new()
creates a new wheel, returning the wheels reference.
event()
is covered in the POE::Wheel manpage.
ListenAccept's event types are AcceptEvent
and ErrorEvent
.
These are the event types this wheel emits and the parameters which are included with each.
ARG0
contains the accepted socket handle. ARG1
contains the accept()
call's return value, which often is the address
of the other end of the socket. ARG2
contains the wheel's unique
ID.
A sample AcceptEvent handler:
sub accept_state { my ($accepted_handle, $remote_address, $wheel_id) = @_[ARG0..ARG2];
# The remote address is always good here. my ($port, $packed_ip) = sockaddr_in($remote_address); my $dotted_quad = inet_ntoa($packed_ip);
print( "Wheel $wheel_id accepted a connection from ", "$dotted_quad port $port.\n" );
# Spawn off a session to interact with the socket. &create_server_session($handle); }
ARG0
contains the name of the operation that failed. This usually
is 'accept'. Note: This is not necessarily a function name.
ARG1
and ARG2
hold numeric and string values for $!
,
respectively. Note: ListenAccept knows how to handle EAGAIN, so it
will never return that error.
ARG3
contains the wheel's unique ID.
A sample ErrorEvent event handler:
sub error_state { my ($operation, $errnum, $errstr, $wheel_id) = @_[ARG0..ARG3]; warn "Wheel $wheel_id generated $operation error $errnum: $errstr\n"; }
POE::Wheel.
The SEE ALSO section in POE contains a table of contents covering the entire POE distribution.
Oh, probably some.
Please see POE for more information about authors and contributors.
POE::Wheel::ListenAccept - accept connections from regular listening sockets |