]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/HTTP.pm
Merge remote-tracking branch 'origin/email-simple-mem' into master
[public-inbox.git] / lib / PublicInbox / HTTP.pm
index 1153ef98779ff6390107afffd3174dacbe3da8f5..5546ac465570d123d19498ef285b385b3b1ba913 100644 (file)
@@ -30,10 +30,8 @@ use constant {
 use Errno qw(EAGAIN);
 
 my $pipelineq = [];
-my $pipet;
 sub process_pipelineq () {
        my $q = $pipelineq;
-       $pipet = undef;
        $pipelineq = [];
        foreach (@$q) {
                next unless $_->{sock};
@@ -58,8 +56,16 @@ sub http_date () {
 sub new ($$$) {
        my ($class, $sock, $addr, $httpd) = @_;
        my $self = fields::new($class);
-       $self->SUPER::new($sock, EPOLLIN | EPOLLONESHOT);
+       my $ev = EPOLLIN;
+       my $wbuf;
+       if (ref($sock) eq 'IO::Socket::SSL' && !$sock->accept_SSL) {
+               return CORE::close($sock) if $! != EAGAIN;
+               $ev = PublicInbox::TLS::epollbit();
+               $wbuf = [ \&PublicInbox::DS::accept_tls_step ];
+       }
+       $self->SUPER::new($sock, $ev | EPOLLONESHOT);
        $self->{httpd} = $httpd;
+       $self->{wbuf} = $wbuf if $wbuf;
        ($self->{remote_addr}, $self->{remote_port}) =
                PublicInbox::Daemon::host_with_port($addr);
        $self;
@@ -95,7 +101,7 @@ sub rbuf_process {
        }
        if ($r < 0) { # incomplete
                $self->rbuf_idle($rbuf);
-               return $self->watch_in1;
+               return $self->requeue;
        }
        $$rbuf = substr($$rbuf, $r);
        my $len = input_prepare($self, \%env);
@@ -238,10 +244,10 @@ sub next_request ($) {
        my ($self) = @_;
        if ($self->{rbuf}) {
                # avoid recursion for pipelined requests
+               PublicInbox::DS::requeue(\&process_pipelineq) if !@$pipelineq;
                push @$pipelineq, $self;
-               $pipet ||= PublicInbox::EvCleanup::asap(*process_pipelineq);
        } else { # wait for next request
-               $self->watch_in1;
+               $self->requeue;
        }
 }
 
@@ -269,7 +275,7 @@ sub getline_cb ($$$) {
                                if ($self->{wbuf}) {
                                        $self->write($next);
                                } else {
-                                       PublicInbox::EvCleanup::asap($next);
+                                       PublicInbox::DS::requeue($next);
                                }
                                return;
                        }
@@ -461,11 +467,4 @@ sub busy () {
        ($self->{rbuf} || $self->{env} || $self->{wbuf});
 }
 
-# fires after pending writes are complete:
-sub restart_pass ($) {
-       $_[0]->{forward}->restart_read; # see PublicInbox::HTTPD::Async
-}
-
-sub enqueue_restart_pass ($) { $_[0]->write(\&restart_pass) }
-
 1;