Salvador Fandiño García > Win32-Socketpair-0.01 > Win32::Socketpair

Download:
Win32-Socketpair-0.01.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  2
Open  1
View/Report Bugs
Module Version: 0.01   Source   Latest Release: Win32-Socketpair-0.02

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.

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.

SEE ALSO ^

IPC::Open2, perlipc, perlfunc.

COPYRIGHT AND LICENSE ^

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.

syntax highlighting: