While instances of the first write(2) failing with EAGAIN
immediately after being returned by accept(2) is highly
unlikely, it still seems like a theoretical possibility. So out
of an abundance of caution, we'll just wait on writability to
reduce branches in our code.
# for IMAP, NNTP, and POP3 which greet clients upon connect
sub greet {
my ($self, $sock) = @_;
- my $ev = EPOLLIN;
- my $wbuf;
+ my $ev = EPOLLOUT;
if ($sock->can('accept_SSL') && !$sock->accept_SSL) {
return if $! != EAGAIN || !($ev = PublicInbox::TLS::epollbit());
- $wbuf = [ \&accept_tls_step, $self->can('do_greet')];
+ $self->{wbuf} = [ \&accept_tls_step ];
}
+ push @{$self->{wbuf}}, $self->can('do_greet');
new($self, $sock, $ev | EPOLLONESHOT);
- if ($wbuf) {
- $self->{wbuf} = $wbuf;
- } else {
- $self->do_greet;
- }
$self;
}