'write_set_watch', # bool: true if we internally set watch_write rather than by a subclass
'closed', # bool: socket is closed
'event_watch', # bitmask of events the client is interested in (POLLIN,OUT,etc.)
- 'writer_func', # subref which does writing. must return bytes written (or undef) and set $! on errors
);
use Errno qw(EINPROGRESS EWOULDBLOCK EISCONN ENOTSOCK
# get up to 1000 events
my $evcount = epoll_wait($Epoll, 1000, $timeout, \@events);
- EVENT:
for ($i=0; $i<$evcount; $i++) {
my $ev = $events[$i];
my $code;
my $state = $ev->[1];
- # if we didn't find a Perlbal::Socket subclass for that fd, try other
- # pseudo-registered (above) fds.
- if (! $pob) {
- my $fd = $ev->[0];
- warn "epoll() returned fd $fd w/ state $state for which we have no mapping. removing.\n";
- epoll_ctl($Epoll, EPOLL_CTL_DEL, $fd, 0);
- POSIX::close($fd);
- next;
- }
-
DebugLevel >= 1 && $class->DebugMsg("Event: fd=%d (%s), state=%d \@ %s\n",
$ev->[0], ref($pob), $ev->[1], time);
$pob = $DescriptorMap{$fd};
- if (!$pob) {
- next;
- }
-
$pob->event_read if $state & POLLIN && ! $pob->{closed};
$pob->event_write if $state & POLLOUT && ! $pob->{closed};
$pob->event_err if $state & POLLERR && ! $pob->{closed};
foreach my $kev (@ret) {
my ($fd, $filter, $flags, $fflags) = @$kev;
my PublicInbox::DS $pob = $DescriptorMap{$fd};
- if (!$pob) {
- warn "kevent() returned fd $fd for which we have no mapping. removing.\n";
- POSIX::close($fd); # close deletes the kevent entry
- next;
- }
DebugLevel >= 1 && $class->DebugMsg("Event: fd=%d (%s), flags=%d \@ %s\n",
$fd, ref($pob), $flags, time);
return $self->{sock};
}
-=head2 C<< $obj->set_writer_func( CODEREF ) >>
-
-Sets a function to use instead of C<syswrite()> when writing data to the socket.
-
-=cut
-sub set_writer_func {
- my PublicInbox::DS $self = shift;
- my $wtr = shift;
- Carp::croak("Not a subref") unless !defined $wtr || UNIVERSAL::isa($wtr, "CODE");
- $self->{writer_func} = $wtr;
-}
-
=head2 C<< $obj->write( $data ) >>
Write the specified data to the underlying handle. I<data> may be scalar,
}
my $to_write = $len - $self->{write_buf_offset};
- my $written;
- if (my $wtr = $self->{writer_func}) {
- $written = $wtr->($bref, $to_write, $self->{write_buf_offset});
- } else {
- $written = syswrite($self->{sock}, $$bref, $to_write, $self->{write_buf_offset});
- }
+ my $written = syswrite($self->{sock}, $$bref, $to_write,
+ $self->{write_buf_offset});
if (! defined $written) {
if ($! == EPIPE) {