Skip to content

Commit

Permalink
MessageTCP: fixed usage of clsocket.
Browse files Browse the repository at this point in the history
  • Loading branch information
stgatilov committed Aug 25, 2020
1 parent fce52e1 commit 1074453
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions radiant/gameconnection/MessageTcp.cpp
Expand Up @@ -124,10 +124,12 @@ void MessageTcp::think() {
char buffer[BUFFER_SIZE];
for (int iter = 0; ; iter++) {
int read = tcp->Receive(BUFFER_SIZE, (uint8*)buffer);
if (read == -1 && tcp->GetSocketError() == CSimpleSocket::SocketEwouldblock)
break; //no more data
if (read == -1)
goto onerror;
goto onerror; //socket error
if (read == 0)
break;
goto onerror; //connection closed on other side
inputBuffer.resize(inputBuffer.size() + read);
memcpy(inputBuffer.data() + inputBuffer.size() - read, buffer, read);
}
Expand All @@ -136,10 +138,12 @@ void MessageTcp::think() {
while (outputPos < outputBuffer.size()) {
int remains = outputBuffer.size() - outputPos;
int written = tcp->Send((uint8*)&outputBuffer[outputPos], remains);
if (written == -1 && tcp->GetSocketError() == CSimpleSocket::SocketEwouldblock)
break; //no more data
if (written == -1)
goto onerror;
goto onerror; //socket error
if (written == 0)
break;
goto onerror; //connection closed on other side
outputPos += written;
}

Expand Down

0 comments on commit 1074453

Please sign in to comment.