Skip to content

Commit ed65f83

Browse files
committed
fix(TCPServer): continues to accept connections after stop() #4892
1 parent 91244ac commit ed65f83

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

Net/src/TCPServer.cpp

+14-7
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ void TCPServer::stop()
116116
{
117117
if (!_stopped)
118118
{
119+
_socket.close();
119120
_stopped = true;
120121
_thread.join();
121122
_pDispatcher->stop();
@@ -150,24 +151,30 @@ void TCPServer::run()
150151
}
151152
catch (Poco::Exception& exc)
152153
{
153-
ErrorHandler::handle(exc);
154+
if (!_stopped)
155+
ErrorHandler::handle(exc);
154156
}
155157
catch (std::exception& exc)
156158
{
157-
ErrorHandler::handle(exc);
159+
if (!_stopped)
160+
ErrorHandler::handle(exc);
158161
}
159162
catch (...)
160163
{
161-
ErrorHandler::handle();
164+
if (!_stopped)
165+
ErrorHandler::handle();
162166
}
163167
}
164168
}
165169
catch (Poco::Exception& exc)
166170
{
167-
ErrorHandler::handle(exc);
168-
// possibly a resource issue since poll() failed;
169-
// give some time to recover before trying again
170-
Poco::Thread::sleep(50);
171+
if (!_stopped)
172+
{
173+
ErrorHandler::handle(exc);
174+
// possibly a resource issue since poll() failed;
175+
// give some time to recover before trying again
176+
Poco::Thread::sleep(50);
177+
}
171178
}
172179
}
173180
}

0 commit comments

Comments
 (0)