diff --git a/includes/tacopie/network/tcp_server.hpp b/includes/tacopie/network/tcp_server.hpp index 59ee7ed..a15b8e0 100644 --- a/includes/tacopie/network/tcp_server.hpp +++ b/includes/tacopie/network/tcp_server.hpp @@ -59,7 +59,7 @@ class tcp_server { //! start & stop the tcp server void start(const std::string& addr, std::uint32_t port, const on_new_connection_callback_t& callback = nullptr); - void stop(void); + void stop(bool wait_for_removal = false, bool recursive_wait_for_removal = true); //! returns whether the server is currently running or not bool is_running(void) const; diff --git a/sources/network/tcp_server.cpp b/sources/network/tcp_server.cpp index 13c4740..33c01eb 100644 --- a/sources/network/tcp_server.cpp +++ b/sources/network/tcp_server.cpp @@ -62,16 +62,19 @@ tcp_server::start(const std::string& host, std::uint32_t port, const on_new_conn } void -tcp_server::stop(void) { +tcp_server::stop(bool wait_for_removal, bool recursive_wait_for_removal) { if (!is_running()) { return; } m_is_running = false; m_io_service->untrack(m_socket); + if (wait_for_removal) { m_io_service->wait_for_removal(m_socket); } m_socket.close(); std::lock_guard lock(m_clients_mtx); - for (auto& client : m_clients) { client->disconnect(); } + for (auto& client : m_clients) { + client->disconnect(recursive_wait_for_removal && wait_for_removal); + } m_clients.clear(); __TACOPIE_LOG(info, "tcp_server stopped");