Reflex::Acceptor - non-blocking client socket acceptor
version 0.060
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(); }
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.
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.
listner
If necessary, the class may later supply a basic socket by default.
Reflex::Role::Accepting explains listener in more detail.
listener
pause() will temporarily stop the server from accepting more clients. See method_pause in Reflex::Role::Accepting for details.
method_pause
resume() will resume a temporarily stopped server so that it may accept more client connections. See method_resume in Reflex::Role::Accepting for details.
method_resume
stop() will permanently stop the server from accepting more clients. See method_stop in Reflex::Role::Accepting for details.
method_stop
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_accept
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.
on_error
Reflex::Acceptor emits events related to accepting client connections. These events are defined by Reflex::Role::Accepting, and they will be explained there.
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.
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.
The SYNOPSIS is an excerpt from eg/eg-34-tcp-server-echo.pl.
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
To install Reflex, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Reflex
CPAN shell
perl -MCPAN -e shell install Reflex
For more information on module installation, please visit the detailed CPAN module installation guide.