NAME
POE::Class::Server::UNIX - Base class to create a POE UNIX Server
SYNOPSIS
#!/usr/bin/perl
use strict;
# A simple echo server on a UNIX socket!
package My::EchoServer;
use POE;
use base 'POE::Class::Conn::UNIXStream';
sub handler_conn_input {
my ($self, $input) = @_[OBJECT, ARG0];
return if $self->get_shutdown;
$self->get_wheel->put($input);
}
package main;
use POE qw/Class::Server::UNIX/;
my $server = new POE::Class::Server::UNIX(
port => 'echo',
conn_class => 'My::EchoServer',
alias => 'echo'
);
# - or -
$server = new POE::Class::Server::UNIX;
$server->set_path('/tmp/foo.sock');
$server->set_conn_class('My::EchoServer');
$server->set_alias('echo');
# - or -
my $server = new POE::Class::Server::UNIX;
$server->configure(
path => '/tmp/foo.sock',
conn_class => 'My::EchoServer',
alias => 'echo'
);
# Creates the session
my $session = $server->start;
printf "Created echo session %d\n", $session->ID;
$poe_kernel->run;
DESCRIPTION
POE::Class::Server::UNIX is a base class for creating POE UNIX Servers. Through inheritance with other POE::Class:: classes it provides a faily simple subclass interface. This document will touch on all methods and handlers within this module and realized though inheritance except for methods in POE::Class.
METHODS
- new
-
The constructor. If takes a hash of arguments which correspond to accessor functions of the same name.
- start
-
Creates the and returns a new session specified by
set_session_type(), defaults to POE::Session. You should setup the connection information before calling this method as the SocketFactory will be created when this is called. Inherited. - disconnect
-
Disconnects the server. This does not kill and current connections POE::Class::Conn for that.
- connect
-
This method creates a POE::Wheel::SocketFactory with current object information from
get_port(),get_address()andget_domain(). The accessorset_wheel()is called with the new SocketFactory. - create_states
-
Creates the following object states in the current session: State Handler error - handler_error connection - handler_connection
- other methods
-
POE::Class for a complete list.
ACCESSOR METHODS
- get_alias
- set_alias
-
Accessor method for the session alias. If no alias is set when
start()is called no alias will be created. Inherited. - get_shutdown
- set_shutdown
-
Accessor method for shutdown. When we are shutdown no more connections will be accepted. This does not mean the session will exit right away. When all connection classes have finished the session will end. Inherited.
- get_session_type
- set_session_type
-
Specifies the class used to created the session when
start()is called. Defaults to POE::Session. - get_path
- set_path
-
Path to the socket file to use.
- get_conn_class
- set_conn_class
-
Sets the connection class used when a new connection is accepted. Defaults to POE::Class::Conn::UNIXStream. You will want to set this to a subclass of POE::Class::Conn::UNIXStream.
- get_wheel
- set_wheel
-
Sets the current wheel, usually a POE::Wheel::SocketFactory. This method is called from
connect()with a POE::Wheel::SocketFactory.
HANDLERS
- handler_start
-
This handler sets a session alias if one was defined and then calles
connect(). - handler_child
-
Cleans up connections stored via
set_connections()andsession_id_to_conn(). - handler_shutdown
-
Sets shutdown to true and calles
disconnect(). - handler_error
-
Warns with the error and calles
disconnect(). - handler_connection
-
Called from POE::Wheel::SocketFactory when a connection is accepted. Creates a new connection object defined by
set_conn_class().
TODO
Write better documentation.
AUTHOR
Scott Beck <sbeck@gossamer-threads.com>
SEE ALSO
POE POE::Class POE::Class::Conn POE::Class::Conn::Stream POE::Class::Conn::UNIXStream