]> Sergey Matveev's repositories - public-inbox.git/commitdiff
httpd/async: set O_NONBLOCK correctly
authorEric Wong <e@80x24.org>
Fri, 5 Feb 2021 00:13:54 +0000 (05:13 +0500)
committerEric Wong <e@80x24.org>
Fri, 5 Feb 2021 00:16:38 +0000 (00:16 +0000)
While Perl tie is nice for some things, getting
IO::Handle->blocking to work transparently with it doesn't
seem possible at the moment.

Add some examples in t/spawn.t for future hackers.

Fixes: 22e51bd9da476fa9 ("qspawn: switch to ProcessPipe via popen_rd")
lib/PublicInbox/HTTPD/Async.pm
t/spawn.t

index bd1fd8faf2c1ea49569a702a16c75407ffd4220e..1de9501d18c43528e4ce634458b394d089d6eb41 100644 (file)
@@ -37,7 +37,8 @@ sub new {
                arg => $arg, # arg for $cb
                end_obj => $end_obj, # like END{}, can ->event_step
        }, $class;
-       IO::Handle::blocking($io, 0);
+       my $pp = tied *$io;
+       $pp->{fh}->blocking(0) // die "$io->blocking(0): $!";
        $self->SUPER::new($io, EPOLLIN | EPOLLET);
 }
 
index 0eed79bbbb5802343717a4590ab2e79406c9ccd6..6f811ec163df75fab559a2c119b723daad23f27f 100644 (file)
--- a/t/spawn.t
+++ b/t/spawn.t
@@ -77,6 +77,11 @@ EOF
 {
        my $fh = popen_rd([qw(printf foo\nbar)]);
        ok(fileno($fh) >= 0, 'tied fileno works');
+       my $tfh = (tied *$fh)->{fh};
+       is($tfh->blocking(0), 1, '->blocking was true');
+       is($tfh->blocking, 0, '->blocking is false');
+       is($tfh->blocking(1), 0, '->blocking was true');
+       is($tfh->blocking, 1, '->blocking is true');
        my @line = <$fh>;
        is_deeply(\@line, [ "foo\n", 'bar' ], 'wantarray works on readline');
 }