Data::FDSet - Syntactic sugar for select() masks
Object-oriented syntax:
my $fdset = Data::FDSet->new(); # These accept either filehandles or file descriptors: $fdset->add( $some_filehandle, fileno($other_fh) ); $fdset->remove( $other_fh ); my $rout = Data::FDSet->new(); my $got = select( $$rout = $$fdset, undef, undef, 10 ); if ($got > 1) { my $fds_to_read_ar = $rout->get_fds(); }
Or, if you’d rather avoid object-oriented syntax:
my $rout = q<>; Data::FDSet::add(\$rout, $some_filehandle, fileno($other_fh)) my $fds_to_read_ar = Data::FDSet::get_fds(\$rout);
This little module makes working with 4-argument select() a bit easier by providing object methods to do the typical operations done on the bitmasks in connection with that function. These methods parallel the functions that C provides to handle struct fd_set.
struct fd_set
A Data::FDSet object is a blessed scalar reference to a bitmask. Unlike with most Perl objects, you may safely reference the object internals, e.g., by doing
$$rout_obj = $rin;
… to replace the bitmask contents. (For this reason, this class defines no method to do the above.)
Instantiates this class. $BITMASK may optionally be passed to initialize the object state.
Empty out the object. Analogous to FD_ZERO(2).
Returns OBJ.
Add one or more file descriptors to the object. Accepts either Perl filehandles or file descriptors. Analogous to FD_SET(2).
The complement of add(). Analogous to FD_CLR(2).
add()
Tests for a file descriptor’s presence in the object. Accepts either a Perl filehandles or a file descriptor. Analogous to FD_ISSET(2).
Returns a reference to an array of the file descriptors that are in the object.
To install Data::FDSet, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::FDSet
CPAN shell
perl -MCPAN -e shell install Data::FDSet
For more information on module installation, please visit the detailed CPAN module installation guide.