Fix RCON disconnect bug

RCON occasionally did NOT disconnect, but only if the socket has been closed improperly. If the server/client crashes for example, the connection remained open in RCON; pendingLen on the initial peek recv < 0 while socket isn't blocking means socket has been closed unexpectedly.
This commit is contained in:
Kawe Mazidjatari 2023-08-04 10:57:39 +02:00
parent 309e297ae4
commit 10ee88ec10

View File

@ -88,6 +88,11 @@ void CNetConBase::Recv(CConnectedNetConsoleData& pData, const int nMaxLen)
Disconnect("remote closed socket");
return;
}
else if (nPendingLen < 0)
{
Disconnect("socket closed unexpectedly");
return;
}
}//////////////////////////////////////////////
int nReadLen = 0; // Find out how much we have to read.
@ -104,7 +109,7 @@ void CNetConBase::Recv(CConnectedNetConsoleData& pData, const int nMaxLen)
const int nRecvLen = ::recv(pData.m_hSocket, szRecvBuf, MIN(sizeof(szRecvBuf), nReadLen), MSG_NOSIGNAL);
if (nRecvLen == 0) // Socket was closed.
{
Disconnect("socket closed unexpectedly");
Disconnect("socket closed");
break;
}
if (nRecvLen < 0 && !m_Socket.IsSocketBlocking())