package Net::Curl::Promiser::Select; use strict; use warnings; =encoding utf-8 =head1 NAME Net::Curl::Promiser::Select =head1 DESCRIPTION This module implements L via Perl’s L built-in. See F in the distribution for a fleshed-out demonstration. This is “the hard way” to do this, by the way. Your life will be simpler if you use (or create) an event-loop-based implementation like L or L. See F for comparisons. =cut #---------------------------------------------------------------------- use parent 'Net::Curl::Promiser'; use Net::Curl::Promiser::Backend::Select; #---------------------------------------------------------------------- =head1 METHODS The following are added in addition to the base class methods: =head2 ($rmask, $wmask, $emask) = I->get_vecs(); Returns the bitmasks to use as input to C. Note that, since these are copies of I’s internal values, you don’t need to copy them again before calling C. =cut sub get_vecs { return shift()->{'backend'}->get_vecs(); } #---------------------------------------------------------------------- =head2 @fds = I->get_fds(); Returns the file descriptors that I tracks—or, in scalar context, the count of such. Useful to check for exception events. =cut sub get_fds { return shift()->{'backend'}->get_fds(); } #---------------------------------------------------------------------- =head2 $obj = I->process( $READ_MASK, $WRITE_MASK ) Tell the underlying L object which socket events have happened. $READ_MASK and $WRITE_MASK are as “left” by Perl’s C built-in. If, in fact, no events have happened, then this calls C on the L object (similar to C). Finally, this reaps whatever pending HTTP responses may be ready and resolves or rejects the corresponding Promise objects. Returns I. =cut sub process { my ($self, @fd_action_args) = @_; $self->{'backend'}->process( $self->{'multi'}, \@fd_action_args ); return $self; } #---------------------------------------------------------------------- =head2 $is_active = I->time_out(); Tell the underlying L object that a timeout happened, and reap whatever pending HTTP responses may be ready. Calls C on the underlying L object. The return is the same as that operation returns. Since C can also do the work of this function, a call to this function is just an optimization. This should only be called from event loop logic. =cut sub time_out { my ($self) = @_; return $self->{'backend'}->time_out( $self->{'multi'} ); } #---------------------------------------------------------------------- =head2 $num = I->get_timeout() Like libcurl’s L, but sometimes returns different values depending on the needs of I. (NB: This value is in I, not milliseconds.) This should only be called (if it’s called at all) from event loop logic. =cut sub get_timeout { my ($self) = @_; my $timeout = $self->{'backend'}->get_timeout( $self->{'multi'} ); return( ($timeout == -1) ? $timeout : $timeout / 1000 ); } #---------------------------------------------------------------------- sub _INIT { return Net::Curl::Promiser::Backend::Select->new(); } 1;