Skip to content

Commit 439e861

Browse files
committed
ircd: Simplify/cleanup the coarse controls for client/server subsystems.
1 parent 225d030 commit 439e861

File tree

5 files changed

+55
-81
lines changed

5 files changed

+55
-81
lines changed

include/ircd/client.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct ircd::client
3737

3838
static void create(const std::shared_ptr<socket> &);
3939
static size_t count(net::ipport remote);
40+
static void terminate_all();
4041
static void interrupt_all();
4142
static void close_all();
4243
static void wait_all();
@@ -106,10 +107,6 @@ struct ircd::client::settings
106107

107108
struct ircd::client::init
108109
{
109-
void interrupt();
110-
void close();
111-
void wait();
112-
113110
init();
114111
~init() noexcept;
115112
};

include/ircd/server/server.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ namespace ircd::server
4848
bool exists(const net::hostport &);
4949
peer &find(const net::hostport &);
5050
peer &get(const net::hostport &);
51+
52+
void interrupt_all();
53+
void close_all();
54+
void wait_all();
5155
}
5256

5357
/// Subsystem initialization / destruction from ircd::main
5458
///
5559
struct ircd::server::init
5660
{
57-
void interrupt();
58-
void close();
59-
void wait();
60-
6161
init();
6262
~init() noexcept;
6363
};

ircd/client.cc

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ noexcept
125125
{
126126
const ctx::uninterruptible::nothrow ui;
127127

128-
interrupt();
129-
close();
130-
wait();
128+
terminate_all();
129+
close_all();
130+
wait_all();
131131

132132
log::debug
133133
{
@@ -137,24 +137,6 @@ noexcept
137137
assert(client::map.empty());
138138
}
139139

140-
void
141-
ircd::client::init::interrupt()
142-
{
143-
interrupt_all();
144-
}
145-
146-
void
147-
ircd::client::init::close()
148-
{
149-
close_all();
150-
}
151-
152-
void
153-
ircd::client::init::wait()
154-
{
155-
wait_all();
156-
}
157-
158140
//
159141
// util
160142
//
@@ -166,19 +148,35 @@ ircd::client::spawn()
166148
}
167149

168150
void
169-
ircd::client::interrupt_all()
151+
ircd::client::wait_all()
170152
{
171153
if(pool.active())
172-
log::warning
154+
log::dwarning
173155
{
174-
"Terminating %zu active of %zu client request contexts; %zu pending; %zu queued",
156+
"Waiting on %zu active of %zu client request contexts; %zu pending; %zu queued.",
175157
pool.active(),
176158
pool.size(),
177159
pool.pending(),
178160
pool.queued()
179161
};
180162

181-
pool.terminate();
163+
while(!client::map.empty())
164+
if(!dock.wait_for(seconds(2)) && !client::map.empty())
165+
log::warning
166+
{
167+
"Waiting for %zu clients to close...", client::map.size()
168+
};
169+
170+
log::debug
171+
{
172+
"Joining %zu active of %zu client request contexts; %zu pending; %zu queued",
173+
pool.active(),
174+
pool.size(),
175+
pool.pending(),
176+
pool.queued()
177+
};
178+
179+
pool.join();
182180
}
183181

184182
void
@@ -211,35 +209,35 @@ ircd::client::close_all()
211209
}
212210

213211
void
214-
ircd::client::wait_all()
212+
ircd::client::interrupt_all()
215213
{
216214
if(pool.active())
217-
log::dwarning
215+
log::warning
218216
{
219-
"Waiting on %zu active of %zu client request contexts; %zu pending; %zu queued.",
217+
"Interrupting %zu active of %zu client request contexts; %zu pending; %zu queued",
220218
pool.active(),
221219
pool.size(),
222220
pool.pending(),
223221
pool.queued()
224222
};
225223

226-
while(!client::map.empty())
227-
if(!dock.wait_for(seconds(2)) && !client::map.empty())
228-
log::warning
229-
{
230-
"Waiting for %zu clients to close...", client::map.size()
231-
};
224+
pool.interrupt();
225+
}
232226

233-
log::debug
234-
{
235-
"Joining %zu active of %zu client request contexts; %zu pending; %zu queued",
236-
pool.active(),
237-
pool.size(),
238-
pool.pending(),
239-
pool.queued()
240-
};
227+
void
228+
ircd::client::terminate_all()
229+
{
230+
if(pool.active())
231+
log::warning
232+
{
233+
"Terminating %zu active of %zu client request contexts; %zu pending; %zu queued",
234+
pool.active(),
235+
pool.size(),
236+
pool.pending(),
237+
pool.queued()
238+
};
241239

242-
pool.join();
240+
pool.terminate();
243241
}
244242

245243
void

ircd/ircd.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,12 @@ noexcept try
229229
const unwind shutdown{[&]
230230
{
231231
_matrix_.close();
232-
_server_.interrupt();
233-
_client_.interrupt();
234-
_server_.close();
235-
_client_.close();
236-
_server_.wait();
237-
_client_.wait();
232+
server::interrupt_all();
233+
client::terminate_all();
234+
server::close_all();
235+
client::close_all();
236+
server::wait_all();
237+
client::wait_all();
238238
}};
239239

240240
// When the call to wait() below completes, IRCd exits from the RUN state.

ircd/server.cc

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ namespace ircd::server
2222

2323
// Internal control
2424
std::unique_ptr<peer> create(const net::hostport &);
25-
void interrupt_all();
26-
void close_all();
27-
void wait_all();
2825
}
2926

3027
decltype(ircd::server::log)
@@ -51,34 +48,16 @@ ircd::server::init::init()
5148
ircd::server::init::~init()
5249
noexcept
5350
{
54-
close();
55-
wait();
51+
interrupt_all();
52+
close_all();
53+
wait_all();
5654
peers.clear();
57-
5855
log::debug
5956
{
6057
log, "All server peers, connections, and requests are clear."
6158
};
6259
}
6360

64-
void
65-
ircd::server::init::wait()
66-
{
67-
wait_all();
68-
}
69-
70-
void
71-
ircd::server::init::close()
72-
{
73-
close_all();
74-
}
75-
76-
void
77-
ircd::server::init::interrupt()
78-
{
79-
interrupt_all();
80-
}
81-
8261
//
8362
// server
8463
//

0 commit comments

Comments
 (0)