delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/06/04/11:07:33

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/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
Date: Tue, 4 Jun 2002 10:59:00 -0400 (EDT)
From: David E Euresti <davie AT MIT DOT EDU>
To: <cygwin AT cygwin DOT com>
Subject: Re: Socket Handles duplicated twice after fork
Message-ID: <Pine.GSO.4.30L.0206041052150.745-100000@scrubbing-bubbles.mit.edu>
MIME-Version: 1.0

Ah the additional handles come from this.

fork call CreateProcess as follows
  rc = CreateProcess (myself->progname, /* image to run */
		      myself->progname, /* what we send in arg0 */
		      sec_attribs,
		      sec_attribs,
		      TRUE,	  /* inherit handles from parent */
		      c_flags,
		      NULL,	  /* environment filled in later */
		      0,	  /* use current drive/directory */
		      &si,
		      &pi);

notice the inherit handles from parent,

fixup_before_fork calls,
 WSADuplicateSocketA (get_socket (), win_proc_id, prot_info_ptr)

now this doesn't actually create a new handle.  It just stores the info in
prot_info_ptr,

but fixup_after_fork calls,
 new_sock = WSASocketA (FROM_PROTOCOL_INFO,
				   FROM_PROTOCOL_INFO,
				   FROM_PROTOCOL_INFO,
				   prot_info_ptr, 0, 0)
and this creates the new handle,
then       set_io_handle ((HANDLE) new_sock);
and the old handle disappears into oblivion.

I don't know why it's written this way.  It would seem easier to just use
the same Duplicated handle from the CreateProcess.  I'm thinking that
maybe on Win9x it doesn't work the same (but I haven't even tested it)

Hope this helps.

David


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.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