]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/IMAP.pm
daemon: use per-listener SIG{__WARN__} callbacks
[public-inbox.git] / lib / PublicInbox / IMAP.pm
index bed633e50789cccb8b1790e29b5d752e6c6ff455..2be1b763f30a89f12e84a8c1fa0339026cf3937d 100644 (file)
@@ -138,6 +138,7 @@ sub login_success ($$) {
 sub auth_challenge_ok ($) {
        my ($self) = @_;
        my $tag = delete($self->{-login_tag}) or return;
+       $self->{anon} = 1;
        login_success($self, $tag);
 }
 
@@ -574,6 +575,16 @@ sub fetch_run_ops {
        $self->msg_more(")\r\n");
 }
 
+sub requeue { # overrides PublicInbox::DS::requeue
+       my ($self) = @_;
+       if ($self->{anon}) { # AUTH=ANONYMOUS gets high priority
+               $self->SUPER::requeue;
+       } else { # low priority
+               push(@{$self->{imapd}->{-authed_q}}, $self) == 1 and
+                       PublicInbox::DS::requeue($self->{imapd});
+       }
+}
+
 sub fetch_blob_cb { # called by git->cat_async via ibx_async_cat
        my ($bref, $oid, $type, $size, $fetch_arg) = @_;
        my ($self, undef, $msgs, $range_info, $ops, $partial) = @$fetch_arg;
@@ -588,10 +599,9 @@ sub fetch_blob_cb { # called by git->cat_async via ibx_async_cat
                $smsg->{blob} eq $oid or die "BUG: $smsg->{blob} != $oid";
        }
        my $pre;
-       if (!$self->{wbuf} && (my $nxt = $msgs->[0])) {
-               $pre = ibx_async_prefetch($ibx, $nxt->{blob},
+       ($self->{anon} && !$self->{wbuf} && $msgs->[0]) and
+               $pre = ibx_async_prefetch($ibx, $msgs->[0]->{blob},
                                        \&fetch_blob_cb, $fetch_arg);
-       }
        fetch_run_ops($self, $smsg, $bref, $ops, $partial);
        $pre ? $self->dflush : $self->requeue_once;
 }
@@ -1176,7 +1186,7 @@ sub out ($$;@) {
 # callback used by PublicInbox::DS for any (e)poll (in/out/hup/err)
 sub event_step {
        my ($self) = @_;
-
+       local $SIG{__WARN__} = $self->{imapd}->{warn_cb};
        return unless $self->flush_write && $self->{sock} && !$self->{long_cb};
 
        # only read more requests if we've drained the write buffer,