I/O Completion Port
-
Worker threads are associated with I/O completion port. Whenever I/O operation completed a thread is invoked. Now when this thread is invoked, how we come to know that which "type" of operation completed whether "read" or write". I think this has to be determined by overlapped structure but i don't know that which "field" of this structure informs about the "type" of operation completed.
-
Worker threads are associated with I/O completion port. Whenever I/O operation completed a thread is invoked. Now when this thread is invoked, how we come to know that which "type" of operation completed whether "read" or write". I think this has to be determined by overlapped structure but i don't know that which "field" of this structure informs about the "type" of operation completed.
bakhtawar wrote: Worker threads are associated with I/O completion port. Whenever I/O operation completed a thread is invoked. Now when this thread is invoked, how we come to know that which "type" of operation completed whether "read" or write". I think this has to be determined by overlapped structure but i don't know that which "field" of this structure informs about the "type" of operation completed. What usually happens is that you don't actually pass only an "overlapped" structure, you pass something that has an overlapped structure in it and also contains other stuff. This allows you to pass anything you like to your thread. Then, once inside your thread you simply convert back from the pointer to the portion of your structure that is an "overlapped" to a pointer to your structure. If you're using C++ then you might define your overlapped like this:
class MyOverlapped : public OVERLAPPED { // include your own data here. };
And then pass it to a read request like this:MyOverlapped *pBuffer; if (SOCKET_ERROR == ::WSARecv( pSocket->m_socket, pBuffer->GetWSABUF(), 1, &dwNumBytes, &dwFlags, pBuffer, NULL))
and retrieve it fromMyOverlapped *pBuffer = 0; GetQueuedCompletionStatus(m_iocp, &dwIoSize, (PDWORD_PTR)&pSocket, (OVERLAPPED**)&pBuffer);
See the code for my reusable C++ socket server class for full details. Len Holgate www.jetbyte.com The right code, right now.