Reimplementing sun.nio.ch.WindowsSelectorImpl using WSAEventSelect and WSAWaitForMultipleEvents instead of a wakeup socket
John Platts
john_platts at hotmail.com
Sat May 19 03:23:24 UTC 2018
The need to allocate a wakeup socket can be eliminated in sun.nio.ch.WindowsSelectorImpl on Windows platforms by reimplementing sun.nio.ch.WindowsSelectorImpl to use the WSAEventSelect and WSAWaitForMultipleEvents APIs introduced in Windows Vista. If WSAEventSelect and WSAWaitForMultipleEvents are used, a wakeup can be done by simply signaling the wakeup event by calling WSASetEvent.
Here is how to do a select using WSAEventSelect and WSAWaitForMultipleEvents on Windows platforms:
1. Allocate events for selection and wakeup by calling the WSACreateEvent() function.
2. Perform a select operation by calling WSAEventSelect method, passing in the event object used for selection.
3. Call the WSAWaitForMultipleEvents function to wait until one of the events is signaled.
4. For the remaining events, call WSAWaitForMultipleEvents with a timeout of 0 to check if the event is signaled.
5. For each of the selection events that are signaled, call the WSAEnumNetworkEvents method to check if the socket is ready for accept, connect, read, or write operations.
6. To cancel selection, call WSAEventSelect with 0 passed into the lNetworkEvents argument (the third argument).
7. Free the events allocated by the WSACreateEvent() function by calling the WSACloseEvent() function.
More information about the core-libs-dev
mailing list