Recently, in UDP communication tests on the iocp model, we found that if the UDP socket on the server directly sends data to a client and the client does not exist
The above getqueuedcompletionstatus will be activated, but an error is returned. The data size is 0,
In addition, if the wsarecvfrom request is sent again, the getqueuedcompletionstatus will be immediately received even if no client sends data.
The returned error message will no longer be able to receive client data. After analysis, you can use the following methods to solve this problem.
To solve this problem, obtain the latest service pack for Windows 2000. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
260910 (http://support.microsoft.com/kb/260910/) How to get the latest Windows 2000 Service Pack
In Windows 2000, a new socket named IOCTL "sio_udp_connreset" was introduced ". Specifically, to obtain the behavior of the original Windows NT 4.0 Windows 2000 when using this ioctl, you must override this program. Windows NT 4.0, Microsoft Windows 95, and Microsoft Windows 98 do not support this new IOCTL. In addition to rewriting the application, you will need to reference the patch further in this article.
The following code snippet demonstrates a technology that can be used to obtain the original Windows NT 4.0 behavior. In the code of the io_udp_connreset control, wsaioctl is called.
DWORDdwBytesReturned = 0;BOOLbNewBehavior = FALSE;DWORDstatus;// disable new behavior using// IOCTL: SIO_UDP_CONNRESETstatus = WSAIoctl(sd, SIO_UDP_CONNRESET,&bNewBehavior, sizeof(bNewBehavior), NULL, 0, &dwBytesReturned, NULL, NULL);if (SOCKET_ERROR == status){DWORD dwErr = WSAGetLastError();if (WSAEWOULDBLOCK == dwErr){// nothing to doreturn(FALSE);}else{printf("WSAIoctl(SIO_UDP_CONNRESET) Error: %d/n", dwErr);return(FALSE);}}
To compile this code, you need to have the latest mswsock. H, including the definition of sio_udp_connreset, or define its direct insert to the code below
// MS Transport Provider IOCTL to control// reporting PORT_UNREACHABLE messages// on UDP sockets via recv/WSARecv/etc.// Path TRUE in input buffer to enable (default if supported),// FALSE to disable.#defineSIO_UDP_CONNRESET_WSAIOW(IOC_VENDOR,12)
Note:The patch described in this article does not resolve this issue unless the program uses the new sio_udp_connreset IOCTL to be overwritten.
For details, see http://support.microsoft.com/kb/263823. you only need to call the following method in UDP socket creation to solve status = wsaioctl (SD, sio_udp_connreset,
& Bnewbehavior, sizeof (bnewbehavior ),
Null, 0, & dwbytesreturned,
Null, null );