From 45e4c21870d02a7ae1d0ee63c9e5e0f23f83102a Mon Sep 17 00:00:00 2001 From: AlexandreRouma Date: Fri, 16 Jul 2021 18:13:18 +0200 Subject: [PATCH] Fixed network lib bug on linux --- core/src/utils/networking.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/core/src/utils/networking.cpp b/core/src/utils/networking.cpp index 658affa5..f8df21b2 100644 --- a/core/src/utils/networking.cpp +++ b/core/src/utils/networking.cpp @@ -61,7 +61,7 @@ namespace net { } int ConnClass::read(int count, uint8_t* buf) { - assert(connectionOpen); + if (!connectionOpen) { return -1; } std::lock_guard lck(readMtx); #ifdef _WIN32 int ret = recv(_sock, (char*)buf, count, 0); @@ -79,7 +79,7 @@ namespace net { } bool ConnClass::write(int count, uint8_t* buf) { - assert(connectionOpen); + if (!connectionOpen) { return false; } std::lock_guard lck(writeMtx); #ifdef _WIN32 int ret = send(_sock, (char*)buf, count, 0); @@ -97,7 +97,7 @@ namespace net { } void ConnClass::readAsync(int count, uint8_t* buf, void (*handler)(int count, uint8_t* buf, void* ctx), void* ctx) { - assert(connectionOpen); + if (!connectionOpen) { return; } // Create entry ConnReadEntry entry; entry.count = count; @@ -116,7 +116,7 @@ namespace net { } void ConnClass::writeAsync(int count, uint8_t* buf) { - assert(connectionOpen); + if (!connectionOpen) { return; } // Create entry ConnWriteEntry entry; entry.count = count; @@ -194,7 +194,7 @@ namespace net { } Conn ListenerClass::accept() { - assert(listening); + if (!listening) { return NULL; } std::lock_guard lck(acceptMtx); Socket _sock; @@ -210,7 +210,7 @@ namespace net { } void ListenerClass::acceptAsync(void (*handler)(Conn conn, void* ctx), void* ctx) { - assert(listening); + if (!listening) { return; } // Create entry ListenerAcceptEntry entry; entry.handler = handler; @@ -231,16 +231,17 @@ namespace net { std::lock_guard lck(acceptQueueMtx); stopWorker = true; } + acceptQueueCnd.notify_all(); if (listening) { #ifdef _WIN32 closesocket(sock); #else + ::shutdown(sock, SHUT_RDWR); ::close(sock); #endif } - acceptQueueCnd.notify_all(); if (acceptWorkerThread.joinable()) { acceptWorkerThread.join(); }