Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: Weirdness with IO::Select and IPC::Open3

by rastoboy (Monk)
on Mar 22, 2011 at 01:41 UTC ( [id://894677]=note: print w/replies, xml ) Need Help??


in reply to Re: Weirdness with IO::Select and IPC::Open3
in thread Weirdness with IO::Select and IPC::Open3

In this case, the OS is ready to communicate to you that you can't read from a write-only handle.

Ikegami, could you by any chance point me to documentation that explains what you're talking about, here? The more I think about it, the less sense it makes, and I'm dying for a doc that just tells me how this system works. I don't even know what "system" I'm talking about, here! :-)

I mean, it seems to me I tell IO::Select to watch these two file handles, one of which has been specified as the STDOUT filehandle for the child process--I just can't grasp how that filehandle should ever show up in can_read().

I know I'm wrong, but I'd like to get properly educated on the subject--I feel like I'm stabbing in the dark, still, know what I mean?

  • Comment on Re^2: Weirdness with IO::Select and IPC::Open3

Replies are listed 'Best First'.
Re^3: Weirdness with IO::Select and IPC::Open3
by ikegami (Patriarch) on Mar 22, 2011 at 02:19 UTC

    The purpose of select is to parallelise a few things including reading from the handles identified by its first argument. As such, select should return whenever sysread would return for any of those handles.

    sysread obviously returns when provided a write-only handle.

    $ perl -E' open(my $fh, ">", "file") or die $!; my $rv = sysread($r[0], $buf, 100); if (!defined($rv)) { say "Error: $!"; } elsif (!$rv) { say "eof"; } else { say "Got $rv bytes"; } ' Error: Bad file descriptor

    As such, select should do the same.

    $ perl -MIO::Select -E' open(my $fh, ">", "file") or die $!; my @r = IO::Select->new($fh)->can_read(); my $rv = sysread($r[0], $buf, 100); if (!defined($rv)) { say "Error: $!"; } elsif (!$rv) { say "eof"; } else { say "Got $rv bytes"; } ' Error: Bad file descriptor

    You're saying select should block forever in the event of an error even though sysread would not. That makes no sense.

      Awesome, and very helpful, thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://894677]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-16 03:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found