]> Sergey Matveev's repositories - public-inbox.git/commitdiff
nntp: wait for writability before sending greeting
authorEric Wong <e@80x24.org>
Mon, 24 Jun 2019 02:52:37 +0000 (02:52 +0000)
committerEric Wong <e@80x24.org>
Mon, 24 Jun 2019 05:26:26 +0000 (05:26 +0000)
This will be needed for NNTPS support, since we need
to negotiate the TLS connection before writing the
greeting and we can reuse the existing buffer layer
to enqueue writes.

lib/PublicInbox/NNTP.pm

index 468a22f529673b2aa0043fdb2d9b92237312b272..a18641d3719f721b9bfe3260002d93da78245773 100644 (file)
@@ -24,7 +24,7 @@ use constant {
        r225 => '225 Headers follow (multi-line)',
        r430 => '430 No article with that message-id',
 };
-use PublicInbox::Syscall qw(EPOLLIN EPOLLONESHOT);
+use PublicInbox::Syscall qw(EPOLLOUT EPOLLONESHOT);
 use Errno qw(EAGAIN);
 
 my @OVERVIEW = qw(Subject From Date Message-ID References Xref);
@@ -98,9 +98,11 @@ sub expire_old () {
 sub new ($$$) {
        my ($class, $sock, $nntpd) = @_;
        my $self = fields::new($class);
-       $self->SUPER::new($sock, EPOLLIN | EPOLLONESHOT);
+       $self->SUPER::new($sock, EPOLLOUT | EPOLLONESHOT);
        $self->{nntpd} = $nntpd;
-       res($self, '201 ' . $nntpd->{servername} . ' ready - post via email');
+       my $greet = "201 $nntpd->{servername} ready - post via email\r\n";
+       open my $fh, '<:scalar',  \$greet or die "open :scalar: $!";
+       $self->{wbuf} = [ $fh ];
        $self->{rbuf} = '';
        update_idle_time($self);
        $expt ||= PublicInbox::EvCleanup::later(*expire_old);