This is the mail archive of the
mailing list for the Cygwin project.
Re: Socket Handles duplicated twice after fork
- From: David E Euresti <davie at MIT dot EDU>
- To: <cygwin at cygwin dot com>
- Date: Tue, 4 Jun 2002 12:44:58 -0400 (EDT)
- Subject: Re: Socket Handles duplicated twice after fork
>The handles are only inherited if they are explicitly marked as
>inheritable. The Cygwin code lives for a long time now under the
>assumption that sockets aren't inheritable if they aren't
>explicitely set to be inheritable (see net.cc, fdsock()).
Hmmm. I think there's a wrong assumption here as you mentioned.
Under Windows NT and Windows 2000, socket handles are inheritable by
default. This feature is often used by a process that wants to spawn a
child process and have the child process interact with the remote
application on the other end of the connection.
Windows 9x differs from Windows NT/Windows 2000 in the following manner:
Socket handles are not inheritable when created. To ensure that a child
process can obtain and use a socket handle created in the parent, the
handle must be explicitly duplicated using the Win32 API DuplicateHandle.
Set the bInheritHandle parameter of the API to TRUE.
Therefore, on Win2k, you are letting them be inherited. So the probably
the right solution is to always inherit, or to always duplicate, but never
do both. Although I don't know maybe we want to inherit in Win2k and
Duplicate in Win9x. (I hate this whole windows versions things)
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html