From 321380eeb8a9ba4853a982558c9076d26aafdf82 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 14 Jun 2024 19:50:41 +0200 Subject: Close socket when stopping the server. Otherwise if we're calling e.g. Socket::run() the server's run() will not terminate on stop(). --- src/lib/server.cc | 5 +++++ src/lib/server.h | 1 + 2 files changed, 6 insertions(+) (limited to 'src') diff --git a/src/lib/server.cc b/src/lib/server.cc index 6e3781dca..359234044 100644 --- a/src/lib/server.cc +++ b/src/lib/server.cc @@ -75,6 +75,8 @@ Server::handle_accept (shared_ptr socket, boost::system::error_code cons return; } + _socket = socket; + handle (socket); start_accept (); } @@ -89,5 +91,8 @@ Server::stop () } _acceptor.close (); + if (auto s = _socket.lock()) { + s->close(); + } _io_service.stop (); } diff --git a/src/lib/server.h b/src/lib/server.h index 0b1950aa7..7e42f6cbd 100644 --- a/src/lib/server.h +++ b/src/lib/server.h @@ -57,6 +57,7 @@ private: boost::asio::io_service _io_service; boost::asio::ip::tcp::acceptor _acceptor; int _timeout; + std::weak_ptr _socket; }; -- cgit v1.2.3