From 439e8618d699ec743825e09342d94e40e1657a5d Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 17 Sep 2018 16:47:36 -0700 Subject: [PATCH] ircd: Simplify/cleanup the coarse controls for client/server subsystems. --- include/ircd/client.h | 5 +- include/ircd/server/server.h | 8 +-- ircd/client.cc | 130 +++++++++++++++++------------------ ircd/ircd.cc | 12 ++-- ircd/server.cc | 27 +------- 5 files changed, 78 insertions(+), 104 deletions(-) diff --git a/include/ircd/client.h b/include/ircd/client.h index 1555268d2..764a1c812 100644 --- a/include/ircd/client.h +++ b/include/ircd/client.h @@ -37,6 +37,7 @@ struct ircd::client static void create(const std::shared_ptr &); static size_t count(net::ipport remote); + static void terminate_all(); static void interrupt_all(); static void close_all(); static void wait_all(); @@ -106,10 +107,6 @@ struct ircd::client::settings struct ircd::client::init { - void interrupt(); - void close(); - void wait(); - init(); ~init() noexcept; }; diff --git a/include/ircd/server/server.h b/include/ircd/server/server.h index fddc97c55..6453ad076 100644 --- a/include/ircd/server/server.h +++ b/include/ircd/server/server.h @@ -48,16 +48,16 @@ namespace ircd::server bool exists(const net::hostport &); peer &find(const net::hostport &); peer &get(const net::hostport &); + + void interrupt_all(); + void close_all(); + void wait_all(); } /// Subsystem initialization / destruction from ircd::main /// struct ircd::server::init { - void interrupt(); - void close(); - void wait(); - init(); ~init() noexcept; }; diff --git a/ircd/client.cc b/ircd/client.cc index 306e6beba..2b94d9c1f 100644 --- a/ircd/client.cc +++ b/ircd/client.cc @@ -125,9 +125,9 @@ noexcept { const ctx::uninterruptible::nothrow ui; - interrupt(); - close(); - wait(); + terminate_all(); + close_all(); + wait_all(); log::debug { @@ -137,24 +137,6 @@ noexcept assert(client::map.empty()); } -void -ircd::client::init::interrupt() -{ - interrupt_all(); -} - -void -ircd::client::init::close() -{ - close_all(); -} - -void -ircd::client::init::wait() -{ - wait_all(); -} - // // util // @@ -165,51 +147,6 @@ ircd::client::spawn() pool.add(size_t(settings.pool_size)); } -void -ircd::client::interrupt_all() -{ - if(pool.active()) - log::warning - { - "Terminating %zu active of %zu client request contexts; %zu pending; %zu queued", - pool.active(), - pool.size(), - pool.pending(), - pool.queued() - }; - - pool.terminate(); -} - -void -ircd::client::close_all() -{ - if(!client::map.empty()) - log::debug - { - "Closing %zu clients", client::map.size() - }; - - auto it(begin(client::map)); - while(it != end(client::map)) - { - auto c(shared_from(*it->second)); ++it; try - { - c->close(net::dc::RST, [c](const auto &e) - { - dock.notify_one(); - }); - } - catch(const std::exception &e) - { - log::derror - { - "Error disconnecting client @%p: %s", c.get(), e.what() - }; - } - } -} - void ircd::client::wait_all() { @@ -242,6 +179,67 @@ ircd::client::wait_all() pool.join(); } +void +ircd::client::close_all() +{ + if(!client::map.empty()) + log::debug + { + "Closing %zu clients", client::map.size() + }; + + auto it(begin(client::map)); + while(it != end(client::map)) + { + auto c(shared_from(*it->second)); ++it; try + { + c->close(net::dc::RST, [c](const auto &e) + { + dock.notify_one(); + }); + } + catch(const std::exception &e) + { + log::derror + { + "Error disconnecting client @%p: %s", c.get(), e.what() + }; + } + } +} + +void +ircd::client::interrupt_all() +{ + if(pool.active()) + log::warning + { + "Interrupting %zu active of %zu client request contexts; %zu pending; %zu queued", + pool.active(), + pool.size(), + pool.pending(), + pool.queued() + }; + + pool.interrupt(); +} + +void +ircd::client::terminate_all() +{ + if(pool.active()) + log::warning + { + "Terminating %zu active of %zu client request contexts; %zu pending; %zu queued", + pool.active(), + pool.size(), + pool.pending(), + pool.queued() + }; + + pool.terminate(); +} + void ircd::client::create(const std::shared_ptr &sock) { diff --git a/ircd/ircd.cc b/ircd/ircd.cc index 55dc2ed46..c4c8cd95a 100644 --- a/ircd/ircd.cc +++ b/ircd/ircd.cc @@ -229,12 +229,12 @@ noexcept try const unwind shutdown{[&] { _matrix_.close(); - _server_.interrupt(); - _client_.interrupt(); - _server_.close(); - _client_.close(); - _server_.wait(); - _client_.wait(); + server::interrupt_all(); + client::terminate_all(); + server::close_all(); + client::close_all(); + server::wait_all(); + client::wait_all(); }}; // When the call to wait() below completes, IRCd exits from the RUN state. diff --git a/ircd/server.cc b/ircd/server.cc index 76d2662a7..665c5ca58 100644 --- a/ircd/server.cc +++ b/ircd/server.cc @@ -22,9 +22,6 @@ namespace ircd::server // Internal control std::unique_ptr create(const net::hostport &); - void interrupt_all(); - void close_all(); - void wait_all(); } decltype(ircd::server::log) @@ -51,34 +48,16 @@ ircd::server::init::init() ircd::server::init::~init() noexcept { - close(); - wait(); + interrupt_all(); + close_all(); + wait_all(); peers.clear(); - log::debug { log, "All server peers, connections, and requests are clear." }; } -void -ircd::server::init::wait() -{ - wait_all(); -} - -void -ircd::server::init::close() -{ - close_all(); -} - -void -ircd::server::init::interrupt() -{ - interrupt_all(); -} - // // server //