The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Data::FDSet - Syntactic sugar for select() masks

SYNOPSIS

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);

DESCRIPTION

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.

INTERFACE NOTE

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.)

METHODS

$obj = CLASS->new( [ $BITMASK ] );

Instantiates this class. $BITMASK may optionally be passed to initialize the object state.

$obj = OBJ->evacuate()

Empty out the object. Analogous to FD_ZERO(2).

Returns OBJ.

$obj = OBJ->add( $FD_OR_FH [, $FD_OR_FH, .. ] )

Add one or more file descriptors to the object. Accepts either Perl filehandles or file descriptors. Analogous to FD_SET(2).

$obj = OBJ->remove( $FD_OR_FH [, $FD_OR_FH, .. ] )

The complement of add(). Analogous to FD_CLR(2).

$yn = OBJ->has( $FD_OR_FH )

Tests for a file descriptor’s presence in the object. Accepts either a Perl filehandles or a file descriptor. Analogous to FD_ISSET(2).

$fds_ar = OBJ->get_fds()

Returns a reference to an array of the file descriptors that are in the object.