GQCS gets notification, when WSAsend returns 0?

半腔热情 提交于 2019-12-11 06:09:42

问题


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.



来源:https://stackoverflow.com/questions/21075102/gqcs-gets-notification-when-wsasend-returns-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!