1 # Copyright (C) 2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # bytecode dispatch pipe, reads a byte, runs a sub
5 # byte => [ sub, @operands ]
6 package PublicInbox::OpPipe;
9 use parent qw(PublicInbox::DS);
10 use PublicInbox::Syscall qw(EPOLLIN);
13 my ($cls, $rd, $op_map, $in_loop) = @_;
14 my $self = bless { sock => $rd, op_map => $op_map }, $cls;
15 # 1031: F_SETPIPE_SZ, 4096: page size
16 fcntl($rd, 1031, 4096) if $^O eq 'linux';
17 if ($in_loop) { # iff using DS->EventLoop
19 $self->SUPER::new($rd, EPOLLIN);
26 my $rd = $self->{sock};
28 until (defined(sysread($rd, $byte, 1))) {
33 my $op = $self->{op_map}->{$byte} or die "BUG: unknown byte `$byte'";
34 if ($byte eq '') { # close on EOF
35 $rd->blocking ? delete($self->{sock}) : $self->close;
37 my ($sub, @args) = @$op;