On Windows, select is only supported for sockets (it's not perl fault but a limitation of the crappy OS).

Some days ago, to solve a similar problem (Windows, pipes and multiplexing IO), I created Win32::Socketpair, a module that emulates socketpair with TCP socket connections going through the localhost interface. For instance:

use Win32::Socketpair 'winopen2'; my ($pid, $socket) = winopen2(@cmd) or die "unable to run command @cmd"; my $fno = fileno $socket; my $v = ''; vec($v, $fno, 1) = 1; while(1) { my $vin = $v; my $vout = length $data ? $v : ''; if (select($vin, $vout, undef, undef)>0) { if (vec($vin, $fno, 1)) { sysread($socket, my $buffer, 2000) or last # closed } if (vec($vout, $fno, 1)) { syswrite($socket, $data) or last # closed } } }

You can also use pipes created this way with IO::Select.

I believe that setting the socket to non-blocking is not needed if you are going to use it exclusively inside a select loop, but anyway, on Windows to set non-blocking mode for a socket you have to use this code:

ioctl($socket, 0x8004667e, 1);
Non-blocking socket read on Windows contains more information on the matter and links to other related nodes.

In reply to Re: Win32 console polling by salva
in thread Win32 console polling by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.