]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei: make pkt_op easier-to-use and understand
authorEric Wong <e@80x24.org>
Sat, 25 Sep 2021 06:17:54 +0000 (06:17 +0000)
committerEric Wong <e@80x24.org>
Sat, 25 Sep 2021 08:53:48 +0000 (08:53 +0000)
Since switching to SOCK_SEQUENTIAL, we no longer have to use
fixed-width records to guarantee atomic reads.  Thus we can
maintain more human-readable/searchable PktOp opcodes.

Furthermore, we can infer the subroutine name in many cases
to avoid repeating ourselves by specifying a command-name
twice (e.g. $ops->{CMD} => [ \&CMD, $obj ]; can now simply be
written as: $ops->{CMD} => [ $obj ]  if CMD is a method of
$obj.

lib/PublicInbox/LEI.pm
lib/PublicInbox/LeiToMail.pm
lib/PublicInbox/LeiXSearch.pm
lib/PublicInbox/PktOp.pm

index 3ff8a347af8bd30735cdc22a4706f0b4c0f9fe89..a337fb0d80c228ab70e2e7014a16164b6deb259f 100644 (file)
@@ -519,8 +519,7 @@ sub fail ($$;$) {
        my ($self, $buf, $exit_code) = @_;
        $self->{failed}++;
        err($self, $buf) if defined $buf;
-       # calls fail_handler
-       $self->{pkt_op_p}->pkt_do('!') if $self->{pkt_op_p};
+       $self->{pkt_op_p}->pkt_do('fail_handler') if $self->{pkt_op_p};
        x_it($self, ($exit_code // 1) << 8);
        undef;
 }
@@ -552,7 +551,7 @@ sub child_error { # passes non-fatal curl exit codes to user
 sub note_sigpipe { # triggers sigpipe_handler
        my ($self, $fd) = @_;
        close(delete($self->{$fd})); # explicit close silences Perl warning
-       $self->{pkt_op_p}->pkt_do('|') if $self->{pkt_op_p};
+       $self->{pkt_op_p}->pkt_do('sigpipe_handler') if $self->{pkt_op_p};
        x_it($self, 13);
 }
 
@@ -614,11 +613,11 @@ sub incr {
 
 sub pkt_ops {
        my ($lei, $ops) = @_;
-       $ops->{'!'} = [ \&fail_handler, $lei ];
-       $ops->{'|'} = [ \&sigpipe_handler, $lei ];
-       $ops->{x_it} = [ \&x_it, $lei ];
-       $ops->{child_error} = [ \&child_error, $lei ];
-       $ops->{incr} = [ \&incr, $lei ];
+       $ops->{fail_handler} = [ $lei ];
+       $ops->{sigpipe_handler} = [ $lei ];
+       $ops->{x_it} = [ $lei ];
+       $ops->{child_error} = [ $lei ];
+       $ops->{incr} = [ $lei ];
        $ops;
 }
 
index 467b27bf275dbf14ae15a8b3f81bff530e2eaf9b..d42759cf71d4d372612fdbc4c79efcf270533e1d 100644 (file)
@@ -714,16 +714,15 @@ sub do_post_auth {
                } else { # Maildir
                        $self->{shard_info} = [ $mod, $shard ];
                }
-               $aug = '+'; # incr_post_augment
+               $aug = 'incr_post_augment';
        } elsif ($self->{-wq_worker_nr} == 0) { # 1st worker do_augment
-               $aug = '.'; # do_post_augment
+               $aug = 'do_post_augment';
        }
        if ($aug) {
                local $0 = 'do_augment';
                eval { do_augment($self, $lei) };
                $lei->fail($@) if $@;
-               $lei->{pkt_op_p}->pkt_do($aug) == 1 or
-                               die "do_post_augment trigger: $!";
+               $lei->{pkt_op_p}->pkt_do($aug) or die "pkt_do($aug): $!";
        }
        # done augmenting, connect the compressor pipe for each worker
        if (my $zpipe = delete $lei->{zpipe}) {
index 99f887ce730f50f21c45f742576164c528217415..ae9f5881676d0a07e40d301c9c81b5356f13d772 100644 (file)
@@ -536,16 +536,16 @@ sub do_query {
        my ($self, $lei) = @_;
        my $l2m = $lei->{l2m};
        my $ops = {
-               '|' => [ $lei->can('sigpipe_handler'), $lei ],
-               '!' => [ $lei->can('fail_handler'), $lei ],
-               '.' => [ \&do_post_augment, $lei ],
-               '+' => [ \&incr_post_augment, $lei ],
+               'sigpipe_handler' => [ $lei ],
+               'fail_handler' => [ $lei ],
+               'do_post_augment' => [ \&do_post_augment, $lei ],
+               'incr_post_augment' => [ \&incr_post_augment, $lei ],
                '' => [ \&query_done, $lei ],
                'mset_progress' => [ \&mset_progress, $lei ],
                'l2m_progress' => [ \&l2m_progress, $lei ],
-               'x_it' => [ $lei->can('x_it'), $lei ],
-               'child_error' => [ $lei->can('child_error'), $lei ],
-               'incr_start_query' => [ \&incr_start_query, $self, $l2m ],
+               'x_it' => [ $lei ],
+               'child_error' => [ $lei ],
+               'incr_start_query' => [ $self, $l2m ],
        };
        $lei->{auth}->op_merge($ops, $l2m) if $l2m && $lei->{auth};
        my $end = $lei->pkt_op_pair;
index 10942dd19b6880335fb465d9de4e3f3113755597..fd2569badd74235a10925dbacc308b4ab30f4fee 100644 (file)
@@ -13,6 +13,7 @@ use Errno qw(EAGAIN EINTR);
 use PublicInbox::Syscall qw(EPOLLIN EPOLLET);
 use Socket qw(AF_UNIX MSG_EOR SOCK_SEQPACKET);
 use PublicInbox::IPC qw(ipc_freeze ipc_thaw);
+use Scalar::Util qw(blessed);
 
 sub new {
        my ($cls, $r) = @_;
@@ -57,8 +58,8 @@ sub event_step {
                }
                my $op = $self->{ops}->{$cmd //= $msg};
                if ($op) {
-                       my ($sub, @args) = @$op;
-                       $sub->(@args, @pargs);
+                       my ($obj, @args) = (@$op, @pargs);
+                       blessed($obj) ? $obj->$cmd(@args) : $obj->(@args);
                } elsif ($msg ne '') {
                        die "BUG: unknown message: `$cmd'";
                }