man POE::Wheel::ListenAccept () - accept connections from regular listening sockets

NAME

POE::Wheel::ListenAccept - accept connections from regular listening sockets

SYNOPSIS

  $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

DESCRIPTION

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.

PUBLIC METHODS

event EVENT_TYPE => EVENT_NAME, ...
event() is covered in the POE::Wheel manpage. ListenAccept's event types are CWAcceptEvent and CWErrorEvent.
ID
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.

EVENT TYPES AND THEIR PARAMETERS

These are the event types this wheel emits and the parameters which are included with each.

AcceptEvent
An AcceptEvent is generated whenever a new connection has been successfully accepted. AcceptEvent is accompanied by three parameters: CWARG0 contains the accepted socket handle. CWARG1 contains the accept() call's return value, which often is the address of the other end of the socket. CWARG2 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);
  }
ErrorEvent
The ErrorEvent event is generated whenever a new connection could not be successfully accepted. Its event is accompanied by four parameters. CWARG0 contains the name of the operation that failed. This usually is 'accept'. Note: This is not necessarily a function name. CWARG1 and CWARG2 hold numeric and string values for CW$!, respectively. Note: ListenAccept knows how to handle EAGAIN, so it will never return that error. CWARG3 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";
  }

SEE ALSO

POE::Wheel.

The SEE ALSO section in POE contains a table of contents covering the entire POE distribution.

BUGS

Oh, probably some.

AUTHORS & COPYRIGHTS

Please see POE for more information about authors and contributors.