Skip Menu |

This queue is for tickets about the IO-Ppoll CPAN distribution.

Report information
The Basics
Id: 106792
Status: resolved
Priority: 0/
Queue: IO-Ppoll

People
Owner: Nobody in particular
Requestors: leonerd-cpan [...] leonerd.org.uk
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.11
Fixed in: 0.12



Subject: Methods to set/clear bitmask fields
Rather than $ppoll->mask( $fh, $ppoll->mask( $fh ) | POLLOUT ) It would be nicer to just $ppoll->mask_set( $fh, POLLOUT ) -- Paul Evans
Added; though named _add and _del, so as not to confuse it with "mask_set" seeming like it sets the entire mask -- Paul Evans
Subject: rt106792.patch
=== modified file 'lib/IO/Ppoll.pm' --- lib/IO/Ppoll.pm 2015-08-31 17:37:05 +0000 +++ lib/IO/Ppoll.pm 2015-08-31 18:07:41 +0000 @@ -125,7 +125,7 @@ if( @_ > 1 ) { if( $newmask ) { $self->{handles}->[$fd] = $handle; - set_events( $self->{fds}, $self->{nfds}, $fd, $newmask ); + mas_events( $self->{fds}, $self->{nfds}, $fd, 0, $newmask ); } else { delete $self->{handles}->[$fd]; @@ -137,6 +137,49 @@ } } +=head2 mask_add + +=head2 mask_del + + $ppoll->mask_add( $handle, $addmask ) + + $ppoll->mask_del( $handle, $delmask ) + +I<Since version 0.12.> + +Convenient shortcuts to setting or clearing one or more bits in the mask of a +handle. Equivalent, respectively, to the following lines + + $ppoll->mask( $handle, $ppoll->mask( $handle ) | $addmask ) + + $ppoll->mask( $handle, $ppoll->mask( $handle ) & ~$delmask ) + +Specifically note that C<$maskbits> contains bits to remove from the mask. + +=cut + +sub mask_add +{ + my $self = shift; + my ( $handle, $addbits ) = @_; + + my $fd = fileno $handle; + defined $fd or croak "Expected a filehandle"; + + mas_events( $self->{fds}, $self->{nfds}, $fd, ~0, $addbits ); +} + +sub mask_del +{ + my $self = shift; + my ( $handle, $delbits ) = @_; + + my $fd = fileno $handle; + defined $fd or croak "Expected a filehandle"; + + mas_events( $self->{fds}, $self->{nfds}, $fd, ~$delbits, 0 ); +} + =head2 poll $ret = $ppoll->poll( $timeout ) === modified file 'lib/IO/Ppoll.xs' --- lib/IO/Ppoll.xs 2012-01-04 23:29:07 +0000 +++ lib/IO/Ppoll.xs 2015-08-31 18:07:41 +0000 @@ -102,17 +102,19 @@ } void -set_events(fds, nfds, fd, newmask) +mas_events(fds, nfds, fd, maskbits, setbits) SV *fds int &nfds int fd - int newmask + int maskbits + int setbits CODE: struct pollfd *fds_real = (struct pollfd *)SvPV_nolen(fds); int i; for(i = 0; i < nfds; i++) { if(fds_real[i].fd == fd) { - fds_real[i].events = newmask; + fds_real[i].events &= maskbits; + fds_real[i].events |= setbits; break; } } @@ -123,7 +125,7 @@ SvPOK_only(fds); fds_real = (struct pollfd *)SvPV(fds, PL_na); fds_real[i].fd = fd; - fds_real[i].events = newmask; + fds_real[i].events = setbits; } OUTPUT: nfds === modified file 't/01handles.t' --- t/01handles.t 2015-08-31 17:30:24 +0000 +++ t/01handles.t 2015-08-31 18:07:41 +0000 @@ -5,7 +5,7 @@ use Test::More; -use IO::Ppoll qw( POLLIN POLLHUP ); +use IO::Ppoll qw( POLLIN POLLOUT POLLHUP ); my $ppoll = IO::Ppoll->new(); @@ -24,6 +24,14 @@ is( $ppoll->mask( \*STDIN ), POLLIN|POLLHUP, 'mask(STDIN) after changing mask' ); +$ppoll->mask_add( \*STDIN, POLLOUT ); + +is( $ppoll->mask( \*STDIN ), POLLIN|POLLOUT|POLLHUP, 'mask(STDIN) after mask_add' ); + +$ppoll->mask_del( \*STDIN, POLLHUP ); + +is( $ppoll->mask( \*STDIN ), POLLIN|POLLOUT, 'mask(STDIN) after mask_del' ); + $ppoll->remove( \*STDIN ); is_deeply( [ $ppoll->handles ], [], 'handles after removing STDIN' );
Released in 0.12 -- Paul Evans