求函数HasConnectionDropped 解读和注释
网上找到的一个函数,侦查判断服务器与客户端通信中断,看的不怎么明白,请大家不吝赐教BOOL CClientSocket::HasConnectionDropped( void )
{
BOOL bConnDropped = FALSE;
INT iRet = 0;
BOOL bOK = TRUE;
struct timeval timeout = { 0, 0 };
fd_set readSocketSet;
FD_ZERO( &readSocketSet );
FD_SET( m_hSocket, &readSocketSet );
iRet = ::select( 0, &readSocketSet, NULL, NULL, &timeout );
bOK = (iRet > 0);
if(bOK)
{
bOK = FD_ISSET( m_hSocket, &readSocketSet );
}
if( bOK )
{
CHAR szBuffer[1] = "";
iRet = ::recv( m_hSocket, szBuffer, 1, MSG_PEEK );
bOK = ( iRet > 0 );
if( !bOK )
{
INT iError = ::WSAGetLastError();
bConnDropped = ( ( iError == WSAENETRESET ) ||
(iError == WSAECONNABORTED ) ||
( iError == WSAECONNRESET ) ||
( iError == WSAEINVAL ) ||
( iRet == 0 ) ); //Graceful disconnect from other side.
}
}
return( bConnDropped );
}