You are viewing the version of this documentation from Perl 5.41.3. This is a development version of Perl.

CONTENTS

NAME

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

SYNOPSIS

use IO::Select;

my $s = IO::Select->new();

$s->add(\*STDIN);
$s->add($some_handle);

my @ready1 = $s->can_read($timeout);

my @ready2 = IO::Select->new(@handles)->can_read(0);

DESCRIPTION

The IO::Select package implements an object approach to the system select function call. It allows the user to see what IO handles, see IO::Handle, are ready for reading, writing or have an exception pending.

CONSTRUCTOR

new ( [ HANDLES ] )

The constructor creates a new object and optionally initialises it with a set of handles.

METHODS

add ( HANDLES )

Add the list of handles to the IO::Select object. It is these values that will be returned when an event occurs. IO::Select keeps these values in a cache which is indexed by the fileno of the handle, so if more than one handle with the same fileno is specified then only the last one is cached.

Each handle can be an IO::Handle object, an integer or an array reference where the first element is an IO::Handle or an integer.

remove ( HANDLES )

Remove all the given handles from the object. This method also works by the fileno of the handles. So the exact handles that were added need not be passed, just handles that have an equivalent fileno

exists ( HANDLE )

Returns a true value (actually the handle itself) if it is present. Returns undef otherwise.

handles

Return an array of all registered handles.

can_read ( [ TIMEOUT ] )

Return an array of handles that are ready for reading. TIMEOUT is the maximum amount of time to wait before returning an empty list (with $! unchanged), in seconds, possibly fractional. If TIMEOUT is not given and any handles are registered then the call will block indefinitely. Upon error, an empty list is returned, with $! set to indicate the error. To distinguish between timeout and error, set $! to zero before calling this method, and check it after an empty list is returned.

can_write ( [ TIMEOUT ] )

Same as can_read except check for handles that can be written to.