about summary refs log tree commit homepage
path: root/lib/PublicInbox/NNTP.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-06-24 02:52:52 +0000
committerEric Wong <e@80x24.org>2019-06-24 05:26:27 +0000
commitce8cdcd68fd899d28b5d7c0354883b0cb33fc4d6 (patch)
tree74a3b85bd90cc2962cdc287467d39fc9ffdbba1e /lib/PublicInbox/NNTP.pm
parent2b18e497086cb92d86d41e842c75feb1a28e9053 (diff)
downloadpublic-inbox-ce8cdcd68fd899d28b5d7c0354883b0cb33fc4d6.tar.gz
A tiny write() for the greeting on a just accept()-ed TCP socket
won't fail with EAGAIN, so we can avoid the extra epoll syscall
traffic with plain sockets.
Diffstat (limited to 'lib/PublicInbox/NNTP.pm')
-rw-r--r--lib/PublicInbox/NNTP.pm18
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index 10a2e158..53e18281 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -24,7 +24,7 @@ use constant {
         r225 =>        '225 Headers follow (multi-line)',
         r430 => '430 No article with that message-id',
 };
-use PublicInbox::Syscall qw(EPOLLOUT EPOLLONESHOT);
+use PublicInbox::Syscall qw(EPOLLIN EPOLLONESHOT);
 use Errno qw(EAGAIN);
 
 my @OVERVIEW = qw(Subject From Date Message-ID References Xref);
@@ -96,17 +96,19 @@ sub greet ($) { $_[0]->write($_[0]->{nntpd}->{greet}) };
 sub new ($$$) {
         my ($class, $sock, $nntpd) = @_;
         my $self = fields::new($class);
-        my $ev = EPOLLOUT | EPOLLONESHOT;
-        my $wbuf = [];
+        my $ev = EPOLLIN;
+        my $wbuf;
         if (ref($sock) eq 'IO::Socket::SSL' && !$sock->accept_SSL) {
                 $ev = PublicInbox::TLS::epollbit() or return CORE::close($sock);
-                $ev |= EPOLLONESHOT;
-                $wbuf->[0] = \&PublicInbox::DS::accept_tls_step;
+                $wbuf = [ \&PublicInbox::DS::accept_tls_step, \&greet ];
         }
-        $self->SUPER::new($sock, $ev);
+        $self->SUPER::new($sock, $ev | EPOLLONESHOT);
         $self->{nntpd} = $nntpd;
-        push @$wbuf, \&greet;
-        $self->{wbuf} = $wbuf;
+        if ($wbuf) {
+                $self->{wbuf} = $wbuf;
+        } else {
+                greet($self);
+        }
         update_idle_time($self);
         $expt ||= PublicInbox::EvCleanup::later(*expire_old);
         $self;