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.
event() is covered in the POE::Wheel manpage.
ListenAccept's event types are AcceptEvent and ErrorEvent.
AcceptEvent
ErrorEvent
The ID method returns a ListenAccept wheel's unique ID. This ID will be included in every event the wheel generates, and it can be used to match events with the wheels which generated them.
These are the event types this wheel emits and the parameters which are included with each.
An AcceptEvent is generated whenever a new connection has been successfully accepted. AcceptEvent is accompanied by three parameters: 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.
ARG0
ARG1
ARG2
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); }
The ErrorEvent event is generated whenever a new connection could not be successfully accepted. Its event is accompanied by four parameters.
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.
ARG3
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.
To install POE, copy and paste the appropriate command in to your terminal.
cpanm
cpanm POE
CPAN shell
perl -MCPAN -e shell install POE
For more information on module installation, please visit the detailed CPAN module installation guide.