Is it possible for WSARecv to have return value of 0 (for a completed
receive) and to return 0 bytes read to indicate a disconnected socket?
In other words, does one have to code for the following situation:
if ( WSARecv(socket,
&wsaBuf,
1,
&dwRead,
&dwFlags,
&overlapped,
NULL
) == 0 ) {
if (dwRead == 0) {
// The client has disconnected!!!
}
}
Pat McNerthney
Icicle Software, Inc.
this is a snippet from my ac::WinTools::C_Socket class:
BOOL C_Socket::WsaRecv( LPWSABUF pWsaBufs,
LPWSAOVERLAPPED pWsaOl,
INT iWsaBufCount )
{
// Get ready to recv data
DWORD dwBytesRecv,
dwFlags = 0;
// Try and recv the data
if ( WSARecv( m_hSocket,
pWsaBufs,
iWsaBufCount,
&dwBytesRecv,
&dwFlags,
pWsaOl,
NULL ) == SOCKET_ERROR )
{
// Get and handle the wsa error
DWORD dwWsaErr = WSAGetLastError();
if ( dwWsaErr != WSA_IO_PENDING )
{
return FALSE;
}
}
return TRUE;
}
If this function returns FALSE you will NOT get any sort completion.
If this function returns TRUE you ARE going to get a completion.
If you get a zero-byte completion from a posted WSARecv it means the client
has disconnected and a graceful shutdown should happen.
> Is it possible for WSARecv to have return value of 0 (for a completed
> receive) and to return 0 bytes read to indicate a disconnected socket?
If you didn't provide WSARecv with a overlapped struct then the operation
could complete with zero-bytes right then and there, or you get a
WSAEWOULDBLOCK which means WSARecv needs to be tried again.
-- CCP
"Patrick J. McNerthney" <p...@mcnerthney.com> wrote in message
news:Y%6t9.197485$U7.52...@twister.socal.rr.com...