in reply to Can't get it working: Bidirectional Pipe on Windows

Consider using Win32::Socketpair instead.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

  • Comment on Re: Can't get it working: Bidirectional Pipe on Windows

Replies are listed 'Best First'.
Re^2: Can't get it working: Bidirectional Pipe on Windows
by salva (Canon) on Mar 09, 2012 at 13:21 UTC
    IIRC, since perl 5.10, the socketpair builtin is also available on Windows (it also emulates it running a TCP connection through localhost), so, is there any reason to prefer using Win32::Socketpair over it?

    I say, because I have not been maintaining Win32::Socketpair for a long time, but maybe it is still useful.

    BTW, does anybody volunteer as its new maintainer?

      is there any reason to prefer using Win32::Socketpair over it?

      It depends whether you're asking about the interface or the implementation.

      I don't know what differences there might be in the implementations, but winsocketpair is obviously easier to use than socketpair.

      my ($fd1, $fd2) = winsocketpair();

      vs

      use Socket qw( AF_UNIX SOCK_STREAM PF_UNSPEC ); socketpair(my $fd1, my $fd2, AF_UNIX, SOCK_STREAM, PF_UNSPEC)

      (Just to make things confusing, it has has to be a UNIX socket, not an INET socket.)

      since perl 5.10, the socketpair builtin is also available on Windows

      I was unaware of that.

      is there any reason to prefer using Win32::Socketpair over it?

      I mostly remember Win32::SocketPair for winopen2(). When I needed bi-di comms with a child process, I found that simply, effective piece of code worked reliably when IPC::Open2, (and the raft of huge & complicated 'portable' modules like IPC::Run with its gargantuan interface, multiple packages and "pump processes"), just hung me out to dry.

      I say, because I have not been maintaining Win32::Socketpair for a long time, but maybe it is still useful.

      I haven't used it for a while, I've only had the need for it once. But I've recommended it a few times without getting negative feedback, so if it ain't broke don't fix it :)


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

      since perl 5.10, the socketpair builtin is also available on Windows
      I should have said that my code is required to run on Activestate Perl 5.8.8.... But thanks for pointing this out.

      -- 
      Ronald Fischer <ynnor@mm.st>
Re^2: Can't get it working: Bidirectional Pipe on Windows
by rovf (Priest) on Mar 09, 2012 at 11:57 UTC
    If I understand this right, Win32::SocketPair would require that the other process also uses sockets. Is this correct? However, the remote process gets the data from stdin and writes the response to stdout....

    -- 
    Ronald Fischer <ynnor@mm.st>

      No. Look at the definition of winopen2. It dups stdin and stdout to the socket pair prior to starting the child process, so it inherits the sockets as its stdin and stdout; it then restore the originals in the parent once the child is running:

      sub winopen2 { my ($pid, $oldin, $oldout); my ($server, $client) = winsocketpair or return undef; open $oldin, '<&', \*STDIN or return (); open $oldout, '>&', \*STDOUT or return (); if (open (STDIN, '<&', $server) and open (STDOUT, '>&', $server)) { $pid = eval { system 1, @_ or die "system command failed: $!"}; # print STDERR "error: $@\n" if $@; } close STDOUT; open STDOUT, '>&', $oldout or carp "unable to reestablish STDOUT"; close STDIN; open STDIN, '<&', $oldin or carp "unable to reestablish STDIN"; #printf STDERR "pid %d, fileno %d, stdout %d, stdin %d\n", # $pid, fileno($client), fileno STDOUT, fileno STDIN; return ($pid and $pid > 0) ? ($pid, $client) : (); }

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

        Great! Thanks a lot! I'll give it a try!

        -- 
        Ronald Fischer <ynnor@mm.st>