https://bugs.winehq.org/show_bug.cgi?id=38399
--- Comment #7 from Sebastian Lackner sebastian@fds-team.de --- (In reply to Bruno Jesus from comment #6)
(In reply to Sebastian Lackner from comment #4)
When I understand the problem correctly, then using a complicated approach with get_sock_fd() and release_sock_fd() is the only way to do it properly with the current design. If ws2_32 code gets moved to ntdll at some point in the future then there might be ways to do it easier.
To use the patch approach I believe your lock free cache patch would be good, to reduce performance impact. I have to test this with much larger select sets to check.
Yes, the patch would definitely help. It will still have the overhead of dup() and close(), but besides that the lookup in the fd cache should be very fast. I am only hesitating a bit to remove all the #ifdefs in my patch, because it will break PowerPC support or make the code significantly larger. :/
The main problem is how to tell if POLLHUP was a misc socket problem, socket closed in other thread or socket didn't connect to server. Windows select call reacts differently to these 3 situations and they are all covered in the tests now. If there was a wine_server_handle_exists( SOCKET2HANDLE(s) ) it could at least eliminate the need for the dup call.
Yes, either something like a wine_server_handle_exists function or alternatively a function to query for the internal ntdll unix file descriptor. In some situations it should also be fine to use the "unsafe" file descriptor, especially because there is no good protection anyway. The dup() is done outside of locking ( http://source.winehq.org/git/wine.git/blob/HEAD:/dlls/ntdll/server.c#l997 ) and might lead to race-conditions when a different thread closes and creates a new file descriptor.