NAME

Win32::Socketpair - Simulate socketpair on Windows

SYNOPSIS

  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";
      }
    }
  }

DESCRIPTION

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.

Also export winopen2() (and winopen2_5()) which use the socketpair to perform a bidirection "piped open" allowing writing to the subprocess' stdin and copturing it stdout (and stderr).

EXPORT

The subroutines that can be imported from this module are:

($fd1, $fd2) = winsocketpair()

creates a socket connection through the localhost interface.

It returns a pair of file descriptors representing both sides of the socket.

($pid, $fd1) = winopen2(@cmd)

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.

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.

($pid, $fd1) = winopen2_5(@cmd)

As above, but also captures stderr as well as stdout. Effectively the same as doing 2>&1, but avoiding the shell.

SEE ALSO

IPC::Open2, perlipc, perlfunc.

COPYRIGHT AND LICENSE

Copyright (C) 2006 Salvador Fandiño <sfandino@yahoo.com>. Copyright (C) 2012 by BrowserUk <cpan.20.browseruk@xoxy.net>

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.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 184:

'=item' outside of any '=over'