Win32::Socketpair - Simulate socketpair on Windows
use Win32::Socketpair 'winopen2'; my $socket = winopen2(@cmd); my $fn = fileno $socket; my $v = ''; vec($v, $fn, 1) = 1; while (1) { if (select(my $vin = $v, my $vout = $v, undef, undef) > 0) { if (vec($vout, $fn, 1) { syswrite($socket, "hello\n") or last; } if (vec($vin, $fn, 1) { sysread($socket, my $buffer, 2048) or last; print "read: $buffer"; } } }
This module allows to create a bidirectional pipe on Windows that can be used inside a select loop. It uses a TCP socket going through the localhost interface to create the connection.
select
The subroutines that can be imported from this module are:
creates a socket connection through the localhost interface.
It returns a pair of file descriptors representing both sides of the socket.
creates a socket connection through the localhost interface and launchs the external command @cmd on the background using one side of the socket as its STDIN and STDOUT.
@cmd
It returns the pid of the new process and the file descriptor for the other side of the socket or an empty list on failure.
IPC::Open2, perlipc, perlfunc.
Copyright (C) 2006 Salvador Fandiño <sfandino@yahoo.com>.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
To install Win32::Socketpair, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Win32::Socketpair
CPAN shell
perl -MCPAN -e shell install Win32::Socketpair
For more information on module installation, please visit the detailed CPAN module installation guide.