Engine: improve CNetConBase::Recv

- ::recv with MSG_PEEK still needs to know the full buffer length.
- Improve disconnect reason.
This commit is contained in:
Kawe Mazidjatari 2025-02-09 16:36:08 +01:00
parent def96b25a7
commit 5d7c94ae2f

View File

@ -298,14 +298,14 @@ void CNetConBase::Recv(CConnectedNetConsoleData& data, const int nMaxLen)
static char szRecvBuf[1024]; static char szRecvBuf[1024];
{////////////////////////////////////////////// {//////////////////////////////////////////////
const int nPendingLen = ::recv(data.m_hSocket, szRecvBuf, sizeof(char), MSG_PEEK); const int nPendingLen = ::recv(data.m_hSocket, szRecvBuf, sizeof(szRecvBuf), MSG_PEEK);
if (nPendingLen == SOCKET_ERROR && m_Socket.IsSocketBlocking()) if (nPendingLen == SOCKET_ERROR && m_Socket.IsSocketBlocking())
{ {
return; return;
} }
else if (nPendingLen == 0) // Socket was closed. else if (nPendingLen == 0) // Socket was closed.
{ {
Disconnect("remote closed socket"); Disconnect("socket closed prematurely");
return; return;
} }
else if (nPendingLen < 0) else if (nPendingLen < 0)
@ -315,8 +315,8 @@ void CNetConBase::Recv(CConnectedNetConsoleData& data, const int nMaxLen)
} }
}////////////////////////////////////////////// }//////////////////////////////////////////////
int nReadLen = 0; // Find out how much we have to read. u_long nReadLen = 0; // Find out how much we have to read.
int iResult = ::ioctlsocket(data.m_hSocket, FIONREAD, reinterpret_cast<u_long*>(&nReadLen)); const int iResult = ::ioctlsocket(data.m_hSocket, FIONREAD, &nReadLen);
if (iResult == SOCKET_ERROR) if (iResult == SOCKET_ERROR)
{ {