I am writing a tcp server on Windows NT using completion ports to use asynchronous I / O. I have a TcpSocket class, a TcpServer class, and some (virtual functions) callbacks to call when an I / O operation is complete, for example. onRead () when reading is completed. I also have onOpen () when the connection is established and onEof () when the connection is closed, and so on. I always have a pending read for the socket, so if the socket efficiently receives data (reading will be completed with size> 0), it calls onRead (), instead, if the client closes the socket on the client side (reading will be completed with size == 0) it calls onEof (), and the server knows when the client closes the socket with closesocket (server_socket); from my side.
Everything works gracefully, but I noticed a thing:
when I call closesocket (client_socket); on the server side of the connection, and not on the client side (either with the linger setting {true, 0} or not), the pending read will be completed as erroneous, that is, the read size will not only == 0, but GetLastError () will return an error : 64 or "ERROR_NETNAME_DELETED". I searched a lot about this on the Internet, but did not find anything interesting.
Then I asked myself: but is this a real mistake? I mean, can this be considered a mistake?
The problem is that on server side the onError () callback will be called when I close (client_socket); instead of onEof (). So I thought about this:
, , "ERROR_NETNAME_DELETED" "", onEof() onError()?
undefined?
, , :
"ERROR_NETNAME_DELETED", OVERLAPPED
, , - > , NTSTATUS
. NTSTATUS [http://www.tenox.tc/links/ntstatus.html]
, "ERROR_NETNAME_DELETED" NTSTATUS 0xC000013B, , "STATUS_LOCAL_DISCONNECT". . "ERROR_IO_PENDING", , .
, OVERLAPPED? , == - 'STATUS_LOCAL_DISCONNECT', onEof()? ?
, , , DisconnectEx()
closesocket (client_socket); . , DisconnectEx()? . (), .