From ed65f839d955931cda3c6b207379343ce8399ff0 Mon Sep 17 00:00:00 2001 From: Alex Fabijanic Date: Tue, 11 Mar 2025 15:36:19 +0100 Subject: [PATCH] fix(TCPServer): continues to accept connections after stop() #4892 --- Net/src/TCPServer.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Net/src/TCPServer.cpp b/Net/src/TCPServer.cpp index ebf48a7e6..94309df89 100644 --- a/Net/src/TCPServer.cpp +++ b/Net/src/TCPServer.cpp @@ -116,6 +116,7 @@ void TCPServer::stop() { if (!_stopped) { + _socket.close(); _stopped = true; _thread.join(); _pDispatcher->stop(); @@ -150,24 +151,30 @@ void TCPServer::run() } catch (Poco::Exception& exc) { - ErrorHandler::handle(exc); + if (!_stopped) + ErrorHandler::handle(exc); } catch (std::exception& exc) { - ErrorHandler::handle(exc); + if (!_stopped) + ErrorHandler::handle(exc); } catch (...) { - ErrorHandler::handle(); + if (!_stopped) + ErrorHandler::handle(); } } } catch (Poco::Exception& exc) { - ErrorHandler::handle(exc); - // possibly a resource issue since poll() failed; - // give some time to recover before trying again - Poco::Thread::sleep(50); + if (!_stopped) + { + ErrorHandler::handle(exc); + // possibly a resource issue since poll() failed; + // give some time to recover before trying again + Poco::Thread::sleep(50); + } } } }