properly handle socket errors in recieving packets

This commit is contained in:
CPunch 2020-08-23 15:09:51 -05:00
parent 561a809f33
commit 8105d0aa88
1 changed files with 10 additions and 1 deletions

View File

@ -78,7 +78,7 @@ bool CNSocket::sendData(uint8_t* data, int size) {
while (sentBytes < size) {
int sent = send(sock, (buffer_t*)(data + sentBytes), size - sentBytes, 0); // no flags defined
if (SOCKETERROR(sent)) {
if (errno == 11 && maxTries > 0) {
if (errno == EAGAIN && maxTries > 0) {
maxTries--;
continue; // try again
}
@ -181,6 +181,10 @@ void CNSocket::step() {
// we'll just leave bufferIndex at 0 since we already have the packet size, it's safe to overwrite those bytes
activelyReading = true;
} else if (errno != EAGAIN) {
// serious socket issue, disconnect connection
kill();
return;
}
}
@ -189,6 +193,11 @@ void CNSocket::step() {
int recved = recv(sock, (buffer_t*)(readBuffer + readBufferIndex), readSize - readBufferIndex, 0);
if (!SOCKETERROR(recved))
readBufferIndex += recved;
else if (errno != EAGAIN) {
// serious socket issue, disconnect connection
kill();
return;
}
}
if (activelyReading && readBufferIndex - readSize <= 0) {