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:
Non-blocking socket read on Windows contains more information on the matter and links to other related nodes.ioctl($socket, 0x8004667e, 1);
In reply to Re: Win32 console polling
by salva
in thread Win32 console polling
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |