Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Unix.(set|clear)_close_on_exec changes sockets to blocking mode #5416
Original bug ID: 5416
Consider the following snippet:
let () =
On Linux 32 bits, the call to accept fails as expected with EAGAIN (EWOULDBLOCK would be fine too).
This issue lies in the Win32 implementation of Unix.(set|clear)_close_on_exec. otherlibs/win32unix/close_on.c uses DuplicateHandle which has the (undocumented) side-effect of resetting sockets to blocking mode.
Note that this trick is from the Win9x era and should probably be replaced by a call to SetHandleInformation.
As a side note, I also noticed the usage of both WinSock and WinSock2 in win32unix. Can I ask what's the point of mixing both ? Do we really need to support Win9X ?
Comment author: @xavierleroy
Patch applied in SVN trunk, commit 11888.
Re: "what's the point of mixing WinSock and WinSock2?", it's probably historical baggage. I don't know what it would imply to switch entirely to WinSock2 (how many changes? what benefits?). If you have suggestions on this topic, feel free to open another PR with them.