'write_buf', # arrayref of scalars, scalarrefs, or coderefs to write
'write_buf_offset', # offset into first array of write_buf to start writing at
'write_buf_size', # total length of data in all write_buf items
- '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.)
);
@ToClose, # sockets to close when event loop is done
$PostLoopCallback, # subref to call at the end of each loop, if defined (global)
- %PLCMap, # fd (num) -> PostLoopCallback (per-object)
$LoopTimeout, # timeout of event loop in milliseconds
$DoneInit, # if we've done the one-time module init yet
@Timers = ();
$PostLoopCallback = undef;
- %PLCMap = ();
$DoneInit = 0;
# NOTE kqueue is close-on-fork, and we don't account for it, yet
sub SetPostLoopCallback {
my ($class, $ref) = @_;
- if (ref $class) {
- # per-object callback
- my PublicInbox::DS $self = $class;
- if (defined $ref && ref $ref eq 'CODE') {
- $PLCMap{$self->{fd}} = $ref;
- } else {
- delete $PLCMap{$self->{fd}};
- }
- } else {
- # global callback
- $PostLoopCallback = (defined $ref && ref $ref eq 'CODE') ? $ref : undef;
- }
+ # global callback
+ $PostLoopCallback = (defined $ref && ref $ref eq 'CODE') ? $ref : undef;
}
# Internal function: run the post-event callback, send read events
# or global) cancels it
my $keep_running = 1;
- # per-object post-loop-callbacks
- for my $plc (values %PLCMap) {
- $keep_running &&= $plc->(\%DescriptorMap);
- }
-
# now we're at the very end, call callback if defined
if (defined $PostLoopCallback) {
$keep_running &&= $PostLoopCallback->(\%DescriptorMap);
}
}
- # now delete from mappings. this fd no longer belongs to us, so we don't want
- # to get alerts for it if it becomes writable/readable/etc.
- delete $PLCMap{$self->{fd}};
-
# we explicitly don't delete from DescriptorMap here until we
# actually close the socket, as we might be in the middle of
# processing an epoll_wait/etc that returned hundreds of fds, one
push @{$self->{write_buf}}, $bref;
$self->{write_buf_size} += $len;
}
- $self->{write_set_watch} = 1 unless $self->{event_watch} & POLLOUT;
$self->watch_write(1);
return 0;
} elsif ($! == ECONNRESET) {
DebugLevel >= 2 && $self->debugmsg("Wrote ALL %d bytes to %d (nq=%d)",
$written, $self->{fd}, $need_queue);
$self->{write_buf_offset} = 0;
-
- if ($self->{write_set_watch}) {
- $self->watch_write(0);
- $self->{write_set_watch} = 0;
- }
+ $self->watch_write(0);
# this was our only write, so we can return immediately
# since we avoided incrementing the buffer size or
sub on_incomplete_write {
my PublicInbox::DS $self = shift;
- $self->{write_set_watch} = 1 unless $self->{event_watch} & POLLOUT;
$self->watch_write(1);
}
$event &= ~POLLOUT if ! $val;
$event |= POLLOUT if $val;
- if ($val && caller ne __PACKAGE__) {
- # A subclass registered interest, it's now responsible for this.
- $self->{write_set_watch} = 0;
- }
-
# If it changed, set it
if ($event != $self->{event_watch}) {
if ($HaveKQueue) {