08 Sep 2012 22:20:51 UTC
- Distribution: Asyncore
- Module version: 0.06
- Source (raw)
- Browse (raw)
- How to Contribute
- Testers (180 / 0 / 0)
- KwaliteeBus factor: 0
- License: open_source
- Perl: v5.8.1
- Activity24 month
- Download (5.47KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest versionSEBA Sebastiano Piccoliand 1 contributors
- Sebastiano Piccoli
Asyncore - basic infrastracture for asynchronous socket services
use Asyncore; use base qw( Asyncore::Dispatcher ); my $server = Asyncore::Dispatcher->new(); $server->create_socket(35000); $server->listen(5); Asyncore::loop();
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
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 argument sets the timeout parameter for the appropriate select() or poll() call, measured in seconds; the default is 30 seconds. [The use_poll parameter, if true, indicates that poll() should be used in preference to select() (the default is False) TBD].
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 subclasses thereof) can freely be mixed in the map. TBD]
This module is a porting of asyncore.py written in python.