From: Eric Wong Date: Wed, 2 Jul 2025 20:43:21 +0000 (+0000) Subject: nntpd|imapd|pop3d: wait on writability, first X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=HEAD;p=thirdparty%2Fpublic-inbox.git nntpd|imapd|pop3d: wait on writability, first 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. --- diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm index 9706d520e..0da84b250 100644 --- a/lib/PublicInbox/DS.pm +++ b/lib/PublicInbox/DS.pm @@ -334,18 +334,13 @@ retry: # 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; }