mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-05 06:50:04 +00:00
Close our end of the connection when we receive an EOF
This should/might fix the server's CPU usage spiking to 100%.
This commit is contained in:
parent
2834891727
commit
974941f4fa
@ -167,7 +167,10 @@ void CNSocket::step() {
|
|||||||
if (readSize <= 0) {
|
if (readSize <= 0) {
|
||||||
// we aren't reading a packet yet, try to start looking for one
|
// we aren't reading a packet yet, try to start looking for one
|
||||||
int recved = recv(sock, (buffer_t*)readBuffer, sizeof(int32_t), 0);
|
int recved = recv(sock, (buffer_t*)readBuffer, sizeof(int32_t), 0);
|
||||||
if (!SOCKETERROR(recved)) {
|
if (recved == 0) {
|
||||||
|
// the socket was closed normally
|
||||||
|
kill();
|
||||||
|
} else if (!SOCKETERROR(recved)) {
|
||||||
// we got our packet size!!!!
|
// we got our packet size!!!!
|
||||||
readSize = *((int32_t*)readBuffer);
|
readSize = *((int32_t*)readBuffer);
|
||||||
// sanity check
|
// sanity check
|
||||||
@ -189,7 +192,10 @@ void CNSocket::step() {
|
|||||||
if (readSize > 0 && readBufferIndex < readSize) {
|
if (readSize > 0 && readBufferIndex < readSize) {
|
||||||
// read until the end of the packet! (or at least try too)
|
// read until the end of the packet! (or at least try too)
|
||||||
int recved = recv(sock, (buffer_t*)(readBuffer + readBufferIndex), readSize - readBufferIndex, 0);
|
int recved = recv(sock, (buffer_t*)(readBuffer + readBufferIndex), readSize - readBufferIndex, 0);
|
||||||
if (!SOCKETERROR(recved))
|
if (recved == 0) {
|
||||||
|
// the socket was closed normally
|
||||||
|
kill();
|
||||||
|
} else if (!SOCKETERROR(recved))
|
||||||
readBufferIndex += recved;
|
readBufferIndex += recved;
|
||||||
else if (OF_ERRNO != OF_EWOULD) {
|
else if (OF_ERRNO != OF_EWOULD) {
|
||||||
// serious socket issue, disconnect connection
|
// serious socket issue, disconnect connection
|
||||||
|
Loading…
Reference in New Issue
Block a user