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
Include classic Unix.select in the Unix module for Win32 #5329
Original bug ID: 5329
It would be helpful if the old "classic" sockets implementation of Unix.select were available. This could be called either Unix.old_select, Unix.fast_select, etc.
The old code from select.c can literally be pasted into the present file: the primitive simply needs to be renamed. For compatibility, the Unix distributions of unix.ml would simply need an alias for Unix.select. The documentation need only make clear that on Windows you can only specify socket descriptors.
While very useful if you need a fully cross-platform version of select, the present implementation is over-kill (and must be slower, even if not relevantly) if all you're after is select on sockets.
Comment author: @xavierleroy
I thought (but haven't checked) that the Win32 implementation of Unix.select has a fast path for the (common) case where all FDs are sockets. If it's not the case, maybe adding such a fast path without changing the Unix interface would be the best solution. A patch would be welcome.
Comment author: @dra27
It doesn't appear to - the only call for sockets is to WSAEventSelect. I'm happy to code a patch (it will probably be after Christmas, though - my time has been squeezed recently but I'm working on an OCaml project again in the new year which is affected by this issue so I argue the dedicate time for helping).
My instinct would be to code it so that the default assumption is all sockets: so adapt fdlist_to_fdset to use Descr_kind_val to test each value as it goes and return 0 if they're all sockets and 1 if a non-socket value is found and use that to build either 3 fd_set values or, if any attempt fails, use the new function instead - does that sound reasonable?
Comment author: @dra27
Patch attached - merges the old unix_select back in as proposed. The patch can be applied with PR5327 (both patches contain an identical fix to windbug.h - so the second one to be applied will fail on that file only). If this patch is applied, the error case in PR5327 can still be seen by adding Unix.stdin to the list of read sockets passed to Unix.select (as that forces the code to use the Sylvain's version of select).
I've not corrected the indentation of the code on lines 1031-1266 as I figured that might cause issues with other pending patches. Those lines should be indented another 4 spaces.