0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +01:00

ircd: Simplify/cleanup the coarse controls for client/server subsystems.

This commit is contained in:
Jason Volk 2018-09-17 16:47:36 -07:00
parent 225d030145
commit 439e8618d6
5 changed files with 78 additions and 104 deletions

View file

@ -37,6 +37,7 @@ struct ircd::client
static void create(const std::shared_ptr<socket> &); static void create(const std::shared_ptr<socket> &);
static size_t count(net::ipport remote); static size_t count(net::ipport remote);
static void terminate_all();
static void interrupt_all(); static void interrupt_all();
static void close_all(); static void close_all();
static void wait_all(); static void wait_all();
@ -106,10 +107,6 @@ struct ircd::client::settings
struct ircd::client::init struct ircd::client::init
{ {
void interrupt();
void close();
void wait();
init(); init();
~init() noexcept; ~init() noexcept;
}; };

View file

@ -48,16 +48,16 @@ namespace ircd::server
bool exists(const net::hostport &); bool exists(const net::hostport &);
peer &find(const net::hostport &); peer &find(const net::hostport &);
peer &get(const net::hostport &); peer &get(const net::hostport &);
void interrupt_all();
void close_all();
void wait_all();
} }
/// Subsystem initialization / destruction from ircd::main /// Subsystem initialization / destruction from ircd::main
/// ///
struct ircd::server::init struct ircd::server::init
{ {
void interrupt();
void close();
void wait();
init(); init();
~init() noexcept; ~init() noexcept;
}; };

View file

@ -125,9 +125,9 @@ noexcept
{ {
const ctx::uninterruptible::nothrow ui; const ctx::uninterruptible::nothrow ui;
interrupt(); terminate_all();
close(); close_all();
wait(); wait_all();
log::debug log::debug
{ {
@ -137,24 +137,6 @@ noexcept
assert(client::map.empty()); 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 // util
// //
@ -165,51 +147,6 @@ ircd::client::spawn()
pool.add(size_t(settings.pool_size)); 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 void
ircd::client::wait_all() ircd::client::wait_all()
{ {
@ -242,6 +179,67 @@ ircd::client::wait_all()
pool.join(); 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 void
ircd::client::create(const std::shared_ptr<socket> &sock) ircd::client::create(const std::shared_ptr<socket> &sock)
{ {

View file

@ -229,12 +229,12 @@ noexcept try
const unwind shutdown{[&] const unwind shutdown{[&]
{ {
_matrix_.close(); _matrix_.close();
_server_.interrupt(); server::interrupt_all();
_client_.interrupt(); client::terminate_all();
_server_.close(); server::close_all();
_client_.close(); client::close_all();
_server_.wait(); server::wait_all();
_client_.wait(); client::wait_all();
}}; }};
// When the call to wait() below completes, IRCd exits from the RUN state. // When the call to wait() below completes, IRCd exits from the RUN state.

View file

@ -22,9 +22,6 @@ namespace ircd::server
// Internal control // Internal control
std::unique_ptr<peer> create(const net::hostport &); std::unique_ptr<peer> create(const net::hostport &);
void interrupt_all();
void close_all();
void wait_all();
} }
decltype(ircd::server::log) decltype(ircd::server::log)
@ -51,34 +48,16 @@ ircd::server::init::init()
ircd::server::init::~init() ircd::server::init::~init()
noexcept noexcept
{ {
close(); interrupt_all();
wait(); close_all();
wait_all();
peers.clear(); peers.clear();
log::debug log::debug
{ {
log, "All server peers, connections, and requests are clear." 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 // server
// //