NAME

POE::Class::Conn - Base class for all connection classes

SYNOPSIS

package My::Conn;

use strict;
use base 'POE::Class::Conn';

use POE qw/
    Class::Server::TCP
    Wheel::ReadWrite
/;

sub new {
    my $class = shift;

    my $self = $class->SUPER::new(@_);

    # Do something

    return $self;
}

sub create_wheel {
    my ($self) = @_;
    $self->wheel(
        POE::Wheel::ReadWrite->new(
            Handle       => $self->get_socket,
            Driver       => $self->get_driver,
            Filter       => $self->get_filter,
            InputEvent   => 'input',
            ErrorEvent   => 'error',
            FlushedEvent => 'flush'
        )
    );
}

sub handler_input {
    my ($self, $input) = @_[OBJECT, ARG0];
    print "Got input: $input\n";
}

package main;

use POE qw/Class::Server::TCP/;

my $server = POE::Class::Server::TCP->new(
    address          => 'localhost',
    connection_class => 'My::Conn'
);
# - or -
my $server = POE::Class::Server::TCP;
$server->configure(
    address          => 'localhost',
    connection_class => 'My::Conn'
);
# - or -
my $server = POE::Class::Server::TCP->new;
$server->set_address('localhost');
$sevrer->set_connection_class('My::Conn');

printf "Created server: %d\n", $server->ID;

# Create the session
my $session = $server->start;
printf "Server session: %d\n", $session->ID;

$poe_kernel->run;

DESCRIPTION

Base class for all POE::Class::Conn classes. Conn classes represent an IO bound connection either server or client.

METHODS

new

The constructor. It takes a hash of arguments which correspond to accessor functions of the same name.

create_states

This method is called from handler_start(). It creates the states needed for IO on the given socket. The states created are:

input - handle socket input
error - handler socket errors
flush - flush events from the socket
shutdown - shutdown this portion of the session
put - send output to the socket

The handlers for these states are explained below.

create_wheel

This is a virtual method. It is called from handler_start() and is expected to create a wheel object and store it with method set_wheel(). $self->get_socket contains the socket you should use. $self->get_filter contains the filter you should use. $self->get_driver contains the driver to use.

disconnect

This method removes the wheel and socket from the object.

ACCESSOR METHODS

All accessors have three methods ala POE::Class::Attribs. set_ATTRIB, get_ATTRIB and ATTRIB. Set and get are obvious. ATTRIB is simply a set/get method. See POE::Class::Attribs for more details.

socket

Stores for the socket.

wheel

Stores for the wheel.

shutdown_on_error

Stores a boolean wether we should shutdown on socket errors.

shutdown

Stores a boolean wether we are being shutdow.

driver

Stores the diver to use for IO. If no driver is defined this creates a new POE::Driver::SysRW, stores it, and returns it.

filter

Stores the filter to use for IO. If no filter is defined this creates a new POE::Filter::Line, stores it, and returns it.

got_error

Set to true if Conn get an error and the shutdown_on_error() flag is set. This is checked in handler_shutdown() and set in handler_error().

HANDLERS

handler_input

This is a virtual state, the subclass must defined it. It is called with the input as ARG0.

handler_put

This state simply takes ARG0 and sends it to $self->get_wheel->put().

handler_error

Called when there is a socket error. Warns the error and shuts down if appropriate.

handler_flush

When the socket is flush this state happens. If we are in a shutdown state calles $self->disconnect.

handler_shutdown

This handler puts us in a shutdown state and calles $self->disconnect if there is no more input pending.

TODO

Write better documentation.

AUTHOR

Scott Beck <sbeck@gossamer-threads.com>

SEE ALSO

POE POE::Class