Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

How to test for reliable select()?

by Lightknight (Beadle)
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.

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://894754]
Approved by moritz
Front-paged by moritz
[Corion]: My Android phone also has /proc/self/ loginuid, but that displays -1 (resp. 4GB). That might be because the phone is rooted.
[tye]: -1 means nobody logged in or the process was started before audit got booted
[davido]: ok, on my ubuntu system getlogin grabs from /proc/self/ loginuid (per strace)
[tye]: disable /proc and then see what it does?
[davido]: then it reads from /etc/passwd to decide who my uid is.
[davido]: sorry, typed that before you asked me to disable proc
[davido]: but you stumped me; don't know how to disable proc.
[tye]: I don't know if you can just dismount, but I thought so.

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2017-06-23 20:00 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (554 votes). Check out past polls.