Overlapped I/O and Completion Port :: Winsock
Okay. I am considering Overlapped I/O and Completion Port I/O models as more robust non-blocking I/O for a Winsock program. Currently I use WSAAsyncSelect. I have some essential questions about the two I/O model.
- Overlapped I/O
Okay. I understand Overlapped I/O with respect to both the event and completion routine. I believe that a primary reason that the completion routine solution of an Overlapped I/O model is more powerful that the event solution is simplicity. For example, the event solution is limited to 64 sockets per worker threads.
Under both solutions and especially the completion routine, how do you associate the socket that caused the overlapped I/O to call the completion routine? In other words, let say socketXYZ triggered overlapped I/O to call its completion routine function. How do you determine inside the routine function that is performing send, recv, etc. on socketXYZ?
- Completion Port I/O
This is really a powerful I/O model and is hands down the best I/O model under NT and newer versions of Windows. I have three essential questions.
1) Lets say there are exactly ten active sockets associated with a completion port. As each socket become inactive via user disconnect, error, etc., how do you know when there are no sockets (zero socket) associated with the completion port? In other words, if you wanted to close a completion port when no socket is associated with it, How do you know when there is no socket associate with it?
2) Given that the call to GetQueuedCompletionStatus() return FALSE (failed), How would you know what sockets to close during cleanup since the completion port had crashed?
Under either Overlapped I/O or Completion Port I/O how do you know when to connect, send, receive, etc. data? For example, in WSAAsyncSelect and WSAAsynEvent, you can can AND check FD_SEND, FD_READ, etc. However, in Overlapped I/O or Completion Port I/O, how do you know if there is data available or when the host/client is ready for you to send data?