]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
nntpd|imapd|pop3d: wait on writability, first master
authorEric Wong <e@80x24.org>
Wed, 2 Jul 2025 20:43:21 +0000 (20:43 +0000)
committerEric Wong <e@80x24.org>
Thu, 3 Jul 2025 09:49:17 +0000 (09:49 +0000)
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

index 9706d520ead357897ec164c7ba1d5b2f2206699e..0da84b250897dc3591864fe7add5e0da9fa48597 100644 (file)
@@ -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;
 }