delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/06/22/03:21:04

X-Spam-Check-By: sourceware.org
Date: Fri, 22 Jun 2007 09:20:42 +0200
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: Socket inheritance with fork/dup2/exec
Message-ID: <20070622072042.GG7379@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <200706212245 DOT l5LMjELU006807 AT chi DOT hcst DOT net>
Mime-Version: 1.0
In-Reply-To: <200706212245.l5LMjELU006807@chi.hcst.net>
User-Agent: Mutt/1.4.2.2i
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On Jun 21 22:45, Jim Powers wrote:
> Hi,
> 
> 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
  hellohellohellohellohello^C

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
terminals.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019