mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-12-23 03:40:05 +00:00
properly handle socket errors in recieving packets
This commit is contained in:
parent
561a809f33
commit
8105d0aa88
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user