Asyncore
view release on metacpan or search on metacpan
lib/Asyncore.pm view on Meta::CPAN
if ($self->{_accepting}) {
return;
}
if (not $self->{_connected}) {
if ($self->{_connecting}) {
$self->handle_connect_event();
}
}
$self->handle_write();
}
sub handle_expt_event {
my $self = shift;
my $err = $self->{_socket}->getsockopt();
if ($err != 0) {
$self->handle_close();
}
else {
$self->handle_expt();
}
}
sub handle_error {
my($self, $error) = @_;
warn $error;
$self->handle_close();
}
sub handle_expt {
# overrided
}
sub handle_read {
# overrided
}
sub handle_write {
# overrided
}
sub handle_connect {
# overrided
}
sub handle_accept {
# overrided
}
1;
__END__
=head1 NAME
Asyncore - basic infrastracture for asynchronous socket services
=head1 SYNOPSIS
use Asyncore;
use base qw( Asyncore::Dispatcher );
my $server = Asyncore::Dispatcher->new();
$server->create_socket();
$server->bind($port)
$server->listen(5);
Asyncore::loop();
=head1 DESCRIPTION
Asyncore is a basic infrastructure for asyncronous socket programming. It provides an implementation of "reactive socket" and it provides hooks for handling events. Code must be written into these hooks (handlers).
Asyncore captures the state of each connection (at the lowest level there is a call to select() and poll()) and it relies on the work to be done on the basis of the connection status (handler).
To manage an asyncronous socket handler instantiate a subclass of Asyncore::Dispatcher and override methods that follow:
writable
readble
handle_connect
handle_accept
handle_read
handle_write
handle_close
handle_expt
handle_error
=head1 METHODS
=head2 Asyncore::loop($timeout, $use_poll, \%map, $count)
Enter a polling loop that terminates after count passes or all open channels have been closed. All arguments are optional. The count parameter defaults to undef, resulting in the loop terminating only when all channels have been closed. The timeout a...
The map parameter is an hash reference whose items are the channels to watch. As channels are closed they are deleted from their map. If map is omitted, a global map is used. Channels (instances of Asyncore::Dispatcher, Asynchat::async_chat() and sub...
=head2 handle_connect()
=head2 handle_accept()
=head2 handle_write()
=head1 ACKNOWLEDGEMENTS
This module is a porting of asyncore.py written in python.
=head1 LICENCE
LGPL
( run in 0.535 second using v1.01-cache-2.11-cpan-39bf76dae61 )