Skip to content

Commit

Permalink
ircd: Simplify/cleanup the coarse controls for client/server subsystems.
Browse files Browse the repository at this point in the history
  • Loading branch information
jevolk committed Sep 17, 2018
1 parent 225d030 commit 439e861
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 81 deletions.
5 changes: 1 addition & 4 deletions include/ircd/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -106,10 +107,6 @@ struct ircd::client::settings

struct ircd::client::init
{
void interrupt();
void close();
void wait();

init();
~init() noexcept;
};
8 changes: 4 additions & 4 deletions include/ircd/server/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
84 changes: 41 additions & 43 deletions ircd/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ noexcept
{
const ctx::uninterruptible::nothrow ui;

interrupt();
close();
wait();
terminate_all();
close_all();
wait_all();

log::debug
{
Expand All @@ -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
//
Expand All @@ -166,19 +148,35 @@ ircd::client::spawn()
}

void
ircd::client::interrupt_all()
ircd::client::wait_all()
{
if(pool.active())
log::warning
log::dwarning
{
"Terminating %zu active of %zu client request contexts; %zu pending; %zu queued",
"Waiting on %zu active of %zu client request contexts; %zu pending; %zu queued.",
pool.active(),
pool.size(),
pool.pending(),
pool.queued()
};

pool.terminate();
while(!client::map.empty())
if(!dock.wait_for(seconds(2)) && !client::map.empty())
log::warning
{
"Waiting for %zu clients to close...", client::map.size()
};

log::debug
{
"Joining %zu active of %zu client request contexts; %zu pending; %zu queued",
pool.active(),
pool.size(),
pool.pending(),
pool.queued()
};

pool.join();
}

void
Expand Down Expand Up @@ -211,35 +209,35 @@ ircd::client::close_all()
}

void
ircd::client::wait_all()
ircd::client::interrupt_all()
{
if(pool.active())
log::dwarning
log::warning
{
"Waiting on %zu active of %zu client request contexts; %zu pending; %zu queued.",
"Interrupting %zu active of %zu client request contexts; %zu pending; %zu queued",
pool.active(),
pool.size(),
pool.pending(),
pool.queued()
};

while(!client::map.empty())
if(!dock.wait_for(seconds(2)) && !client::map.empty())
log::warning
{
"Waiting for %zu clients to close...", client::map.size()
};
pool.interrupt();
}

log::debug
{
"Joining %zu active of %zu client request contexts; %zu pending; %zu queued",
pool.active(),
pool.size(),
pool.pending(),
pool.queued()
};
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.join();
pool.terminate();
}

void
Expand Down
12 changes: 6 additions & 6 deletions ircd/ircd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 3 additions & 24 deletions ircd/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
//
Expand Down

0 comments on commit 439e861

Please sign in to comment.