]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/DS.pm
ds: move requeue_once
[public-inbox.git] / lib / PublicInbox / DS.pm
index bf8c4466218a37a43688aaaca2b063c65e98c86e..f0181b5461cfc4111574af2991d3522a57aba174 100644 (file)
@@ -347,6 +347,24 @@ retry:
     $DescriptorMap{$fd} = $self;
 }
 
+# for IMAP, NNTP, and POP3 which greet clients upon connect
+sub greet {
+       my ($self, $sock) = @_;
+       my $ev = EPOLLIN;
+       my $wbuf;
+       if ($sock->can('accept_SSL') && !$sock->accept_SSL) {
+               return CORE::close($sock) if $! != EAGAIN;
+               $ev = PublicInbox::TLS::epollbit() or return CORE::close($sock);
+               $wbuf = [ \&accept_tls_step, $self->can('do_greet')];
+       }
+       new($self, $sock, $ev | EPOLLONESHOT);
+       if ($wbuf) {
+               $self->{wbuf} = $wbuf;
+       } else {
+               $self->do_greet;
+       }
+       $self;
+}
 
 #####################################################################
 ### I N S T A N C E   M E T H O D S
@@ -630,6 +648,22 @@ sub shutdn ($) {
     }
 }
 
+sub zflush {} # overridden by NNTPdeflate and IMAPdeflate
+
+sub requeue_once {
+       my ($self) = @_;
+       # COMPRESS users all share the same DEFLATE context.
+       # Flush it here to ensure clients don't see
+       # each other's data
+       $self->zflush;
+
+       # no recursion, schedule another call ASAP,
+       # but only after all pending writes are done.
+       # autovivify wbuf.  wbuf may be populated by $cb,
+       # no need to rearm if so: (push returns new size of array)
+       requeue($self) if push(@{$self->{wbuf}}, $self->can('long_step')) == 1;
+}
+
 sub dwaitpid ($;$$) {
        my ($pid, $cb, $arg) = @_;
        if ($in_loop) {