--- Danga-Socket-1.57/Socket.pm 2007-04-16 14:55:56.000000000 -0400 +++ lib/Danga/Socket.pm 2007-12-03 11:42:35.000000000 -0500 @@ -259,7 +259,17 @@ =cut sub OtherFds { my $class = shift; - if ( @_ ) { %OtherFds = @_ } + if ( @_ ) { + # Delete Existing + foreach my $fd (keys %OtherFds) { + $class->DelOtherFds($fd); + } + my %hash = @_; + # Add New + foreach my $fd (keys %hash) { + $class->AddOtherFds($fd=>$hash{$fd}); + } + } return wantarray ? %OtherFds : \%OtherFds; } @@ -270,10 +280,42 @@ =cut sub AddOtherFds { my $class = shift; - %OtherFds = ( %OtherFds, @_ ); # FIXME investigate what happens on dupe fds + my %hash = @_; + foreach my $fd (keys %hash) { + # delete if FD already in otherfds + $class->DelOtherFds($fd); + # Add hash in epoll/kqueue contexts + if ($HaveEpoll) { + if (epoll_ctl($Epoll, EPOLL_CTL_ADD, $fd, EPOLLIN) == -1) { + warn "epoll_ctl(): failure adding fd=$fd; $! (", $!+0, ")\n"; + } + } elsif ($HaveKQueue) { + $KQueue->EV_SET($fd, IO::KQueue::EVFILT_READ(), IO::KQueue::EV_ADD()); + } + } + %OtherFds = ( %OtherFds, %hash ); return wantarray ? %OtherFds : \%OtherFds; } +=head2 C<< CLASS->DelOtherFds( [%fdmap] ) >> + +Remove fds from the OtherFds hash for processing + +=cut +sub DelOtherFds { + my $class = shift; + foreach my $fd ( @_ ) { + if ($OtherFds{$fd}) { + if ($HaveEpoll) { + if (epoll_ctl($Epoll, EPOLL_CTL_DEL, $fd, EPOLLIN)) { + warn("epoll_ctl(): failure deleting fd=$fd during _cleanup(); $! (" . ($!+0) . ")\n"); + } + } + delete $OtherFds{$fd}; + } + } +} + =head2 C<< CLASS->SetLoopTimeout( $timeout ) >> Set the loop timeout for the event loop to some value in milliseconds.