NAME
Reflex::Acceptor - non-blocking client socket acceptor
VERSION
version 0.060
SYNOPSIS
package TcpEchoServer;
use Moose;
extends 'Reflex::Acceptor';
use Reflex::Collection;
use EchoStream; # See eg directory.
has clients => (
is => 'rw',
isa => 'Reflex::Collection',
default => sub { Reflex::Collection->new() },
handles => { remember_client => "remember" },
);
sub on_accept {
my ($self, $args) = @_;
$self->remember_client(
EchoStream->new(
handle => $args->{socket},
rd => 1,
)
);
}
sub on_error {
my ($self, $args) = @_;
warn "$args->{errfun} error $args->{errnum}: $args->{errstr}\n";
$self->stop();
}
DESCRIPTION
Reflex::Acceptor takes a listening socket and produces new sockets for clients that connect to it. It is almost entirely implemented in Reflex::Role::Accepting. That role's documentation contains important details that won't be covered here.
Public Attributes
listener
Reflex::Acceptor defines a single attribute, listner
, which should be set to a listening socket of some kind. Reflex::Acceptor requires an externally supplied socket so that the user may specify any and all applicable socket options.
If necessary, the class may later supply a basic socket by default.
Reflex::Role::Accepting explains listener
in more detail.
Public Methods
pause
pause() will temporarily stop the server from accepting more clients. See method_pause
in Reflex::Role::Accepting for details.
resume
resume() will resume a temporarily stopped server so that it may accept more client connections. See method_resume
in Reflex::Role::Accepting for details.
stop
stop() will permanently stop the server from accepting more clients. See method_stop
in Reflex::Role::Accepting for details.
Callbacks
on_accept
on_accept
is called whenever Perl's built-in accept() function returns a socket. Reflex::Role::Accepting explains the data returned with on_accept
. If necessary, that role will also define a default on_accept
handler that emits an "accept" event.
on_error
on_error
is called whenever Perl's built-in accept() function returns an error. Reflex::Role::Accepting explains the data returned with on_error
. If necessary, that role will also define a default on_error
handler that emits an "error" event.
Public Events
Reflex::Acceptor emits events related to accepting client connections. These events are defined by Reflex::Role::Accepting, and they will be explained there.
accept
If no on_accept
handler is set, then Reflex::Acceptor will emit an "accept" event for every client connection accepted. Reflex::Role::Accepting explains this event in more detail.
error
If no on_error
handler is set, then Reflex::Acceptor will emit an "error" event every time accept() returns an error. Reflex::Role::Accepting explains this event in more detail.
EXAMPLES
The SYNOPSIS is an excerpt from eg/eg-34-tcp-server-echo.pl.
SEE ALSO
Reflex Reflex::Role::Accepting Reflex::Role::Connecting Reflex::Connector
"ACKNOWLEDGEMENTS" in Reflex "ASSISTANCE" in Reflex "AUTHORS" in Reflex "BUGS" in Reflex "BUGS" in Reflex "CONTRIBUTORS" in Reflex "COPYRIGHT" in Reflex "LICENSE" in Reflex "TODO" in Reflex