I am trying to upgrade my C++ TCP client program to be compatible with Windows 7. The program is set to use non-blocking socket and it works OK for Windows XP. However, when I ran the same code in Windows 7 and found that recv function in the socket class behaves differently.
When I try to disconnect the ethernet cable from the PC, both Windows XP and Windows 7 detects that the network is disconnected in the system tray. However,
In Windows XP, recv returns SOCKET_ERROR and WSAGetLastError returns WSAECONNRESET
In Windows 7, recv returns SOCKET_ERROR but WSAGetLastError returns WSAEWOULDBLOCK
I am curious why socket recv function still thinks that the socket is still connected (i.e. return WSAEWOULDBLOCK) and only detects there is a disconnection after keepalive timed out.
Also is there any alternative way to detect the network is disconnected using TCP socket library apart from checking the value of WSAGetLastError after calling recv function?
Many thanks!