Carp::cluck("undef sock and/or fd in PublicInbox::DS->new. sock=" . ($sock || "") . ", fd=" . ($fd || ""))
unless $sock && $fd;
- $self->{wbuf} = [];
-
my $ev = $self->{event_watch} = POLLERR|POLLHUP|POLLNVAL;
_InitPoller();
# we need to flush our write buffer, as there may
# be self-referential closures (sub { $client->close })
# preventing the object from being destroyed
- @{$self->{wbuf}} = ();
+ delete $self->{wbuf};
# if we're using epoll, we have to remove this from our epoll fd so we stop getting
# notifications about it
if ($HaveEpoll) {
my $fd = fileno($sock);
- epoll_ctl($Epoll, EPOLL_CTL_DEL, $fd, $self->{event_watch}) and
+ epoll_ctl($Epoll, EPOLL_CTL_DEL, $fd, 0) and
confess("EPOLL_CTL_DEL: $!");
}
# returns 1 if done, 0 if incomplete
sub flush_write ($) {
my ($self) = @_;
+ my $wbuf = $self->{wbuf} or return 1;
my $sock = $self->{sock} or return 1;
- my $wbuf = $self->{wbuf};
while (my $bref = $wbuf->[0]) {
my $ref = ref($bref);
}
} # while @$wbuf
+ delete $self->{wbuf};
$self->watch_write(0);
1; # all done
}
my $sock = $self->{sock} or return 1;
my $ref = ref $data;
my $bref = $ref ? $data : \$data;
- my $wbuf = $self->{wbuf};
- if (@$wbuf) { # already buffering, can't write more...
+ if (my $wbuf = $self->{wbuf}) { # already buffering, can't write more...
push @$wbuf, $bref;
return 0;
} elsif ($ref eq 'CODE') {
if (defined $written) {
return 1 if $written == $to_write;
$self->{wbuf_off} = $written;
- push @$wbuf, $bref;
+ $self->{wbuf} = [ $bref ];
return flush_write($self); # try until EAGAIN
} elsif ($! == EAGAIN) {
- push @$wbuf, $bref;
+ $self->{wbuf} = [ $bref ];
$self->watch_write(1);
} else {
$self->close;