touched up TcpServer termination

This commit is contained in:
hyung-hwan 2018-07-02 13:02:27 +00:00
parent d7a27d4a84
commit 1d9054af17

View File

@ -54,13 +54,12 @@ int TcpServer::Worker::main ()
try { n = this->listener->server->handle_worker(this); } try { n = this->listener->server->handle_worker(this); }
catch (...) { n = -1; } catch (...) { n = -1; }
this->csspl.lock ();
this->socket.close ();
this->csspl.unlock ();
TcpServer* server = this->getServer(); TcpServer* server = this->getServer();
server->worker_list_spl.lock (); server->worker_list_spl.lock ();
this->csspl.lock ();
this->socket.close ();
this->csspl.unlock ();
if (!this->claimed) if (!this->claimed)
{ {
server->worker_list[Worker::LIVE].remove (this); server->worker_list[Worker::LIVE].remove (this);
@ -77,11 +76,6 @@ int TcpServer::Worker::stop () QSE_CPP_NOEXCEPT
// the connection by the socket's closing. // the connection by the socket's closing.
// therefore, handle_worker() must return // therefore, handle_worker() must return
// when it detects the end of the connection. // when it detects the end of the connection.
//
// TODO: must think of a better way to do this
// as it might not be thread-safe.
// but it is still ok because Worker::stop()
// is rarely called.
this->csspl.lock (); this->csspl.lock ();
this->socket.shutdown (); this->socket.shutdown ();
this->csspl.unlock (); this->csspl.unlock ();
@ -464,11 +458,11 @@ void TcpServer::delete_all_workers (Worker::State state) QSE_CPP_NOEXCEPT
{ {
this->worker_list[state].remove (worker); this->worker_list[state].remove (worker);
worker->claimed = true; worker->claimed = true;
worker->stop();
} }
this->worker_list_spl.unlock(); this->worker_list_spl.unlock();
if (!worker) break; if (!worker) break;
worker->stop();
worker->join (); worker->join ();
this->release_wid (worker); this->release_wid (worker);