Skip to content
This repository has been archived by the owner on Apr 6, 2019. It is now read-only.

Commit

Permalink
[2.3.0] add wait_for_removal mechanism to the tcp_server
Browse files Browse the repository at this point in the history
  • Loading branch information
Cylix committed Apr 10, 2017
1 parent fafcf39 commit add305a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion includes/tacopie/network/tcp_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions sources/network/tcp_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> 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");
Expand Down

0 comments on commit add305a

Please sign in to comment.