Open sockets non-overlapped?

Lev Bishop
Fri May 19 15:19:00 GMT 2006

Here's a trivial little patch for your consideration (while I wait for
my copyright assignment to go through).

It makes it so that cygwin sockets can be passed usefully to windows
processes. Eg:
$ cmd /c dir > /dev/tcp/localhost/5001
However, it's not perfect -- if the windows process just exits, then
the connection is reset, not shut down gracefully. Playing with
SO_LINGER doesn't seem to help here. Only way I can think of to make
it work would be to have the cygwin stub that waits for windows
processes to exit, to keep a handle on the socket, poll for when the
windows process closes the socket (using NtQuerySystemInformation
SystemHandleInformation?) and when it does, close down the socket

Anyway, this adds new functionality and doesn't seem to break anything
that worked before.

2006-05-15 Lev Bishop <>
	* (cygwin_socket): Don't open socket for overlapped IO.
-------------- next part --------------
Index: cygwin/
RCS file: /cvs/src/src/winsup/cygwin/,v
retrieving revision 1.206
diff -u -p -r1.206
--- cygwin/	5 Apr 2006 16:53:12 -0000	1.206
+++ cygwin/	19 May 2006 04:24:05 -0000
@@ -578,7 +578,7 @@ cygwin_socket (int af, int type, int pro
   debug_printf ("socket (%d, %d, %d)", af, type, protocol);
-  soc = socket (AF_INET, type, af == AF_LOCAL ? 0 : protocol);
+  soc = WSASocket (AF_INET, type, af == AF_LOCAL ? 0 : protocol, 0, 0, 0);
   if (soc == INVALID_SOCKET)

More information about the Cygwin-patches mailing list