From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id A07311F4B6 for ; Mon, 24 Jun 2019 02:59:24 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 51/57] nntp: send greeting immediately for plain sockets Date: Mon, 24 Jun 2019 02:52:52 +0000 Message-Id: <20190624025258.25592-52-e@80x24.org> In-Reply-To: <20190624025258.25592-1-e@80x24.org> References: <20190624025258.25592-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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. --- lib/PublicInbox/NNTP.pm | 18 ++++++++++-------- 1 file 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; -- EW