I am using winapi function WSARecvFrom to receive UDP data on a socket, I am using overlapped IO with IOCP ports.
In the documentation its stated:
If no error occurs and the receive operation has completed immediately, WSARecvFrom returns zero.
And in the remarks:
If an overlapped operation completes immediately, WSARecvFrom returns a value of zero and the lpNumberOfBytesRecvd parameter is updated with the number of bytes received and the flag bits pointed by the lpFlags parameter are also updated. If the overlapped operation is successfully initiated and will complete later, WSARecvFrom returns SOCKET_ERROR and indicates error code WSA_IO_PENDING. In this case, lpNumberOfBytesRecvd and lpFlags is not updated.
However if the function returns 0 the buffers are not updated with any new data, but the InternalHigh member of OVERLAPPED struct (which is the same as lpNumberOfBytesRecvd parameter, but for OVERLAPPED IO it should be NULL as per docs) is updated with a different number (which I assume is the correct number of bytes)
I have found in a forum from quite a while ago some people said when using WSARecvFrom with UDP and IOCP and it returns 0 it should just be ignored, is this really the case?
Should WSARecvFrom returning 0 for UDP with IOCP be ignored, if not, why would the documentation be so unclear?
I have also heard that IOCP is a superset of Overlapped IO and that is why im refering it to as such in this thread (im not sure if its really the case but this thread seems to confirm it)
WSA api behavior not depend from - are socket bind to IOCP or not. it depend from asynchronous (frequently it called Overlapped) I/O used or not.
this is absolute nonsense. IOCP and Overlapped(asynchronous) I/O different things. IOCP (xor APC and Event) is means to receive a notification when I/O is complete.
of course no. must not be ignored any return code.
unclear what you mean.
this is not true. when I/O is completed without error - buffers is updated. if you think it not updated - possible you bad check, pass wrong pointers to api, or may be you send data which already in buffers - say you send 0 bytes and 0 already in buffers. wihout view concrete code - impossible say.
the general rule for overlapped I/O: