mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 07:23:53 +01:00
ircd: Simplify/cleanup the coarse controls for client/server subsystems.
This commit is contained in:
parent
225d030145
commit
439e8618d6
5 changed files with 78 additions and 104 deletions
|
@ -37,6 +37,7 @@ struct ircd::client
|
|||
|
||||
static void create(const std::shared_ptr<socket> &);
|
||||
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;
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
130
ircd/client.cc
130
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<socket> &sock)
|
||||
{
|
||||
|
|
12
ircd/ircd.cc
12
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.
|
||||
|
|
|
@ -22,9 +22,6 @@ namespace ircd::server
|
|||
|
||||
// Internal control
|
||||
std::unique_ptr<peer> 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
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue