Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005416OCaml~DO NOT USE (was: OCaml general)public2011-12-08 14:112013-08-31 12:48
Assigned To 
PlatformPCOSWindowsOS VersionXP SP3 32 bits
Product Version3.12.1 
Target VersionFixed in Version 
Summary0005416: Unix.(set|clear)_close_on_exec changes sockets to blocking mode
DescriptionConsider the following snippet:

let () =
  let server = Unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 in
    Unix.set_nonblock server;
    Unix.set_close_on_exec server;
    Unix.setsockopt server Unix.SO_REUSEADDR true;
    Unix.bind server (Unix.ADDR_INET (Unix.inet_addr_any, 1039));
    Unix.listen server 10;
      output_string stdout "calling Unix.accept on non-blocking socket\n";
      flush stdout;
      ignore (Unix.accept server)

On Linux 32 bits, the call to accept fails as expected with EAGAIN (EWOULDBLOCK would be fine too).
On WinXP SP3 32 bits, the call to accept blocks.

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 ?
TagsNo tags attached.
Attached Filespatch file icon ocaml-3.12.1.close_on.patch [^] (935 bytes) 2011-12-08 14:43 [Show Content]

- Relationships
related to 0004895closed Windows (mingw): Unix.set/clear_close_on_exec modifies the descriptor 

-  Notes
xleroy (administrator)
2011-12-20 10:01

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.

- Issue History
Date Modified Username Field Change
2011-12-08 14:11 ripoche New Issue
2011-12-08 14:43 ripoche File Added: ocaml-3.12.1.close_on.patch
2011-12-20 10:01 xleroy Note Added: 0006399
2011-12-20 10:01 xleroy Status new => resolved
2011-12-20 10:01 xleroy Resolution open => fixed
2012-02-27 18:14 xleroy Relationship added related to 0004895
2013-08-31 12:48 xleroy Status resolved => closed
2017-02-23 16:36 doligez Category OCaml general => -OCaml general
2017-03-03 17:55 doligez Category -OCaml general => -(deprecated) general
2017-03-03 18:01 doligez Category -(deprecated) general => ~deprecated (was: OCaml general)
2017-03-06 17:04 doligez Category ~deprecated (was: OCaml general) => ~DO NOT USE (was: OCaml general)

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker