X-Spam-Check-By: sourceware.org Message-ID: <467B040A.11443EF4@dessent.net> Date: Thu, 21 Jun 2007 16:04:42 -0700 From: Brian Dessent X-Mailer: Mozilla 4.79 [en] (Windows NT 5.0; U) MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: Socket inheritance with fork/dup2/exec References: <200706212245 DOT l5LMjELU006807 AT chi DOT hcst DOT net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Reply-To: cygwin AT cygwin DOT com Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com 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'm fairly sure this isn't supposed to work. Unix domain sockets (AF_UNIX/AF_LOCAL) don't actually exist in any Windows API so Cygwin emulates them with an underlying AF_INET socket. So when your MSVCRT program tries to WriteFile to a socket it fails, because you have to use the Winsock API for that. In short, Windows is not unix, and handles aren't fds. You can probably make this work if you use pipe() instead of a socketpair() as that maps directly onto a Windows anonymous pipe, which is a file handle that can be written to. You could also use a named pipe, which is the closest Windows has to a unix domain socket, but there is no corresponding POSIX api for that and so you'd be breaking abstraction as you'd have to deal with raw Win32 APIs in your POSIX parent app, which is ugly (and not how Cygwin was designed to work either.) Brian -- 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/