Subject: | Watching handles and O_NONBLOCK |
So as suggested, I put a quick patch in to report when ->watch_io is given a blocking filehandle, and we seem to hit that a few times in tests... not sure whether the loop should silently "fix" that.
The warning triggers 414 times in the core IO::Async testsuite, many of those will be duplicates but it does seem to indicate that there's a few paths to cover.
cheers,
Tom
Subject: | 2015-02-10-report-blocking-fh.diff |
diff --git a/lib/IO/Async/Loop/Poll.pm b/lib/IO/Async/Loop/Poll.pm
index a1154d3..7af2a28 100644
--- a/lib/IO/Async/Loop/Poll.pm
+++ b/lib/IO/Async/Loop/Poll.pm
@@ -246,6 +246,18 @@ sub watch_io
my $poll = $self->{poll};
my $handle = $params{handle};
+ {
+ use Fcntl qw(F_GETFL O_NONBLOCK);
+
+ my $flags = fcntl($handle, F_GETFL, 0)
+ or die "Can't get flags for the socket: $!\n";
+ warn sprintf("Watching a handle in blocking mode [%s] from %s\n", $handle, join(':', (caller)[1,2])) unless O_NONBLOCK == ($flags & O_NONBLOCK);
+
+ if(0) { # might want to try this as well...?
+ $flags = fcntl($handle, F_SETFL, $flags | O_NONBLOCK)
+ or die "Can't set flags for the socket: $!\n";
+ }
+ }
my $curmask = $poll->mask( $handle ) || 0;
diff --git a/lib/IO/Async/Loop/Select.pm b/lib/IO/Async/Loop/Select.pm
index 37ff60d..55660bd 100644
--- a/lib/IO/Async/Loop/Select.pm
+++ b/lib/IO/Async/Loop/Select.pm
@@ -241,6 +241,19 @@ sub watch_io
my %params = @_;
$self->__watch_io( %params );
+ {
+ my $handle = $params{handle};
+ use Fcntl qw(F_GETFL O_NONBLOCK);
+
+ my $flags = fcntl($handle, F_GETFL, 0)
+ or die "Can't get flags for the socket: $!\n";
+ warn sprintf("Watching a handle in blocking mode [%s] from %s\n", $handle, join(':', (caller)[1,2])) unless O_NONBLOCK == ($flags & O_NONBLOCK);
+
+ if(0) { # might want to try this as well...?
+ $flags = fcntl($handle, F_SETFL, $flags | O_NONBLOCK)
+ or die "Can't set flags for the socket: $!\n";
+ }
+ }
my $fileno = $params{handle}->fileno;
Subject: | blocking.log |
Message body is not shown because it is too large.