Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

How to test for reliable select()?

by Lightknight (Sexton)
on Mar 22, 2011 at 09:53 UTC ( #894754=perlquestion: print w/ replies, xml ) Need Help??
Lightknight has asked for the wisdom of the Perl Monks concerning the following question:

I'm writing a module, Parallel::Loops, that now uses IO::Select on a pipe's handles. However select only works on windows for sockets. And perlport says that:
       select  Only implemented on sockets. (Win32, VMS)
               Only reliable on sockets. (RISC OS)
I guess I could test for Win32 || VMS || RISC_OS somehow (by finding what $^O is on all those platforms?). But that is brittle. Is there "a better way" to judge whether select works without having to fork and without it costing (too much) runtime? ($Config{d_select} eq 'define') seems to be true for both linux and Windows, unhelpfully.

Comment on How to test for reliable select()?
Re: How to test for reliable select()?
by BrowserUk (Pope) on Mar 22, 2011 at 10:08 UTC
    Is there "a better way" to judge whether select works without having to fork and without it costing (too much) runtime?

    This is as much a question as a suggestion.

    On an OS where select does work on pipes, if you create a pipe, write to the write handle and then immediately select on the read handle with a timeout, shouldn't you get the read handle's fileno returned immediately? On Windows, you get 0:

    pipe $in, $out;; print $out 'fred';; $si = ''; vec $si, fileno( $in ), 1;; print select $si, undef, undef, 0.1;; 0 0.1

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: How to test for reliable select()?
by ambrus (Abbot) on Mar 22, 2011 at 11:22 UTC

    You might also try to use a proper portable event module like EV which will do as much as it can on many platforms including Win32.

Re: How to test for reliable select()?
by ikegami (Pope) on Mar 22, 2011 at 17:20 UTC

    Sockets can be used instead of pipes. The following works on Windows (and on unix, of course):

    use Socket qw( AF_UNIX SOCK_STREAM PF_UNSPEC ); sub _pipe { socketpair($_[0], $_[1], AF_UNIX, SOCK_STREAM, PF_UNSPEC) or return undef; shutdown($_[0], 1); # No more writing for reader shutdown($_[1], 0); # No more reading for writer return 1; }

    (From Re^4: why IPC::Open3 can't execute MS-DOS "dir" command?)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://894754]
Approved by moritz
Front-paged by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2014-12-26 03:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (164 votes), past polls