IO::Async::Loop::Select.3pm

Langue: en

Version: 2010-06-09 (fedora - 01/12/10)

Section: 3 (Bibliothèques de fonctions)

NAME

"IO::Async::Loop::Select" - use "IO::Async" with "select(2)"

SYNOPSIS

  use IO::Async::Loop::Select;
 
  my $loop = IO::Async::Loop::Select->new();
 
  $loop->add( ... );
 
  $loop->loop_forever();
 
 

Or

  while(1) {
     $loop->loop_once();
     ...
  }
 
 

Or

  while(1) {
     my ( $rvec, $wvec, $evec ) = ('') x 3;
     my $timeout;
 
     $loop->pre_select( \$rvec, \$wvec, \$evec, \$timeout );
     ...
     my $ret = select( $rvec, $wvec, $evec, $timeout );
     ...
     $loop->post_select( $rvec, $evec, $wvec );
  }
 
 

DESCRIPTION

This subclass of "IO::Async::Loop" uses the "select()" syscall to perform read-ready and write-ready tests.

To integrate with an existing "select()"-based event loop, a pair of methods "pre_select()" and "post_select()" can be called immediately before and after a "select()" call. The relevant bit in the read-ready bitvector is always set by the "pre_select()" method, but the corresponding bit in write-ready vector is set depending on the state of the 'want_writeready' property. The "post_select()" method will invoke the "on_read_ready()" or "on_write_ready()" methods or callbacks as appropriate.

CONSTRUCTOR

$loop = IO::Async::Loop::Select->new()

This function returns a new instance of a "IO::Async::Loop::Select" object. It takes no special arguments.

METHODS

$loop->pre_select( \$readvec, \$writevec, \$exceptvec, \$timeout )

This method prepares the bitvectors for a "select()" call, setting the bits that notifiers registered by this loop are interested in. It will always set the appropriate bits in the read vector, but will only set them in the write vector if the notifier's "want_writeready()" property is true. Neither the exception vector nor the timeout are affected.
\$readvec
\$writevec
\$exceptvec
Scalar references to the reading, writing and exception bitvectors
\$timeout
Scalar reference to the timeout value

$loop->post_select( $readvec, $writevec, $exceptvec )

This method checks the returned bitvectors from a "select()" call, and calls any of the notification methods or callbacks that are appropriate.
$readvec
$writevec
$exceptvec
Scalars containing the read-ready, write-ready and exception bitvectors

$count = $loop->loop_once( $timeout )

This method calls the "pre_select()" method to prepare the bitvectors for a "select()" syscall, performs it, then calls "post_select()" to process the result. It returns the total number of callbacks invoked by the "post_select()" method, or "undef" if the underlying "select()" syscall returned an error.

SEE ALSO

*
IO::Select - OO interface to select system call

AUTHOR

Paul Evans <leonerd@leonerd.org.uk>