GQCS gets notification, when WSAsend returns 0?

2019-08-15 06:08发布

问题:

Although I have read a lot about WSAsend (msdn), I still need some clarifications.

Part of my code:

   int rc;
   rc=WSASend(Socket,....);

   if (rc==0) {....}
   else if ((rc == SOCKET_ERROR) && (WSA_IO_PENDING != (err = WSAGetLastError()))) 
          {
           printf("WSASend failed with error: %d Socket(%d) \n", err,(pTmp1->Socket));
           ....
          }

There is said in msdn that WSAsend operation may sometimes completes immediately returning zero (it never happened during my test server ). So if this happens, the GetQueuedCompletionStatus will get notification?

Thanks in advance.

回答1:

If any socket API call which initiates an overlapped operation which will generate a completion to an I/O completion port when completed returns 0 then a completion IS generated and posted to the IOCP. See this Microsoft knowledge base article for details. Thus you need no special handling for the non error return case.

Except...

If you are using SetFileCompletionNotificationMode() to set the the FILE_SKIP_COMPLETION_PORT_ON_SUCCESS mode. In which case a return value of 0 does NOT cause normal completion handling and you need to do your completion handling after the successful API call.



标签: send iocp