When you create an IOCP port, you should initialize the connection monitor, which is nothing difference with the general socket, of course, you have to associate it into the IOCP, otherwise you will not respond from IOCP. Then you will create a request for receiving requests. This will receive a connection.
If there is a connection coming in, you will receive the request packet issued in the getQueuedCompletionStatus function, then the data listening, or number of requests can be performed. The data that can be sent and received.
I have always wanted to figure out the transformation between several states. The first is to connect from the listening state to the connection, and then go to the data transmission. Then go to the connection to turn it off. How is the IOCP to mark a connection is closed?
After looking for MSDN help documents, I finally found it. To mark a connection to close, to see two things, a getQueuedCompletionStatus function is 0 lpnumberofbytes to 0, and the other is the getLastError function returns Error_Success. Above After the two conditions are satisfied, I know that Socket is closed.