Mailing-List: contact cygwin-developers-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , 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" 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) Content-Type: text/plain; charset="iso-8859-1" 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