--- name: IO::Select runtime: pp source: src/native/IO/Select/pp.rs --- ```{index} single: IO::Select; Perl module (pp runtime) ``` # IO::Select Native implementation of IO::Select Provides multiplexed I/O via the POSIX select() system call, compatible with Perl's IO::Select module. IO::Select objects are blessed hashrefs internally storing: - `__fds`: an Av mapping fd_number -> stored handle (the original Sv) - `__count`: integer count of registered handles # Functions ## new Constructor. Creates an IO::Select object, optionally pre-populated with an initial set of handles. ```perl use IO::Select; my $sel = IO::Select->new(); my $sel = IO::Select->new($fh1, $fh2); ``` ## add Adds one or more handles to the select set. Returns the number of handles added. ```perl $sel->add($fh); $sel->add(\*STDIN, $sock); ``` ## remove Removes one or more handles from the select set. Returns the number of handles removed. ```perl $sel->remove($fh); ``` ## count Returns the number of handles currently registered. ```perl my $n = $sel->count(); ``` ## handles Returns a list of all registered handles. ```perl my @fhs = $sel->handles(); ``` ## exists Checks if a given handle is in the select set. Returns the stored handle if present, undef otherwise. ```perl if (defined $sel->exists($fh)) { ... } ``` ## bits Returns the vec-style bitmask string suitable for the 4-argument `select()` builtin. Returns undef if the set is empty. ```perl my $bits = $sel->bits(); ``` ## can_read Returns a list of handles that are ready for reading within the given timeout (seconds, fractional allowed). ```perl my @ready = $sel->can_read(0.5); ``` ## can_write Returns a list of handles that are ready for writing within the given timeout. ```perl my @ready = $sel->can_write(1.0); ``` ## has_exception Returns a list of handles that have pending exceptions within the given timeout. ```perl my @exc = $sel->has_exception(0); ``` ## select Static/class method. Performs a POSIX `select(2)` across up to three IO::Select objects (readers, writers, errors) with a timeout. Returns three arrayrefs of ready handles, or an empty list on timeout. ```perl my ($r, $w, $e) = IO::Select->select($readers, $writers, $errors, $timeout); ```