This is the mail archive of the
mailing list for the Cygwin project.
Re: Socket inheritance with fork/dup2/exec
- From: Corinna Vinschen <corinna-cygwin at cygwin dot com>
- To: cygwin at cygwin dot com
- Date: Fri, 22 Jun 2007 09:20:42 +0200
- Subject: Re: Socket inheritance with fork/dup2/exec
- References: <200706212245.l5LMjELU006807@chi.hcst.net>
- Reply-to: cygwin at cygwin dot com
On Jun 21 22:45, Jim Powers wrote:
> I am redirecting the stdout of a child process to a socket via the standard
> fork/dup2/exec paradigm and then reading and displaying the output.
> This works fine if the exec'd child process is compiled using gcc under
> cygwin. However, it fails with an "Invalid file handle" error when compiled
> using VC8 under windows.
> I've included both the parent and child code below.
> I am running cygwin 1.5.24 and gcc3.4.4.
This is almost certainly a drawback of the method used for duplicating
sockets to child processes used in Cygwin 1.5.24 and before
(WSADuplicateSocket/WSASocket). This only works reliable if the child
knows that the descriptor is a socket. Usually server applications
using sockets don't duplicate the socket to the child processes, but
instead use pipes or pseudo terminals on the local connection, so that's
not a standard problem.
However, the next version of Cygwin will use standard DuplicateHandle
calls as for normal file handles. Consequentially your
your test application appears to work with a Cygwin built from CVS:
$ ./sock-cyg-win-parent ./sock-cyg-win-child.exe
You could try a developer snapshot from http://cygwin.com/snapshots/
As a workaround for Cygwin 1.5.x, use pipes, as already noted, or pseudo
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Project Co-Leader cygwin AT cygwin DOT com
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html