delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/2000/04/14/12:14:13

Mailing-List: contact cygwin-developers-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-developers-subscribe AT sourceware DOT cygnus DOT com>
List-Archive: <http://sourceware.cygnus.com/ml/cygwin-developers/>
List-Post: <mailto:cygwin-developers AT sourceware DOT cygnus DOT com>
List-Help: <mailto:cygwin-developers-help AT sourceware DOT cygnus DOT com>, <http://sourceware.cygnus.com/ml/#faqs>
Sender: cygwin-developers-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin-developers AT sourceware DOT cygnus DOT com
Message-ID: <779F20BCCE5AD31186A50008C75D9979171712@SILLDN_MAIL1>
From: "Fifer, Eric" <EFifer AT sanwaint DOT com>
To: cygwin-developers AT sourceware DOT cygnus DOT com
Subject: sockets and close-on-exec (F_SETFD)
Date: Fri, 14 Apr 2000 18:13:15 +0100
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2650.21)

I have some socket code that does the typical series of
socket, bind, listen, accept, connect, and close calls.
The sockets are marked for close-on-exec with
fcntl(fd, F_SETFD, 1).  Unfortunately, in some circumstances,
not entirely deterministic, a bind fails with EINVAL
(which according to MSDN means the socket is already
bound to an address).

After a lot of tracing, I found that the close-on-exec flag
uses code in set_inheritance that does a CloseHandle (after
a DuplicateHandle) instead of a closesocket.  In my code,
handles end up getting reused because they have been previously
closed (either with closesocket or CloseHandle).  However,
bind seems to be extra-fussy and unless the reused handle
was closed with a closesocket it fails with WSAEINVAL.

I added some code so that set_inheritance can call
closesocket if a handle is a socket and my problem
goes away.  Similarly, if I don't use close-on-exec
the problem goes away.

Does this make any sense?

Thanks.

Eric Fifer

- Raw text -


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