]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/PktOp.pm
lei: propagate curl errors, improve internal consistency
[public-inbox.git] / lib / PublicInbox / PktOp.pm
index 40c7262a3848d01dd222b9e0b715d7b982eb0e0a..10d76da0536b18064fcbf4874698f5e76da9ea7e 100644 (file)
@@ -4,8 +4,7 @@
 # op dispatch socket, reads a message, runs a sub
 # There may be multiple producers, but (for now) only one consumer
 # Used for lei_xsearch and maybe other things
-# "literal" => [ sub, @operands ]
-# /regexp/ => [ sub, @operands ]
+# "command" => [ $sub, @fixed_operands ]
 package PublicInbox::PktOp;
 use strict;
 use v5.10.1;
@@ -57,11 +56,19 @@ sub event_step {
                        $self->close;
                        die "recv: $!";
                }
-               my ($cmd, $pargs) = split(/\0/, $msg, 2);
+               my ($cmd, @pargs);
+               if (index($msg, "\0") > 0) {
+                       ($cmd, my $pargs) = split(/\0/, $msg, 2);
+                       @pargs = @{ipc_thaw($pargs)};
+               } else {
+                       # for compatibility with the script/lei in client mode,
+                       # it doesn't load Sereal||Storable for startup speed
+                       ($cmd, @pargs) = split(/ /, $msg);
+               }
                my $op = $self->{ops}->{$cmd //= $msg};
                die "BUG: unknown message: `$cmd'" unless $op;
                my ($sub, @args) = @$op;
-               $sub->(@args, $pargs ? ipc_thaw($pargs) : ());
+               $sub->(@args, @pargs);
                return $self->close if $msg eq ''; # close on EOF
        } while (1);
 }