From a0d0cf02f8fedd562de076da6f51fd7ddff9cdd3 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 2 Jul 2025 20:43:21 +0000 Subject: [PATCH] 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. --- lib/PublicInbox/DS.pm | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) 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; } -- 2.39.5