nghttpx: Define ~Config for automatic clean up with std::unique_ptr
Now config global is backed with std::unique_ptr. configuration swapping dance is now a bit cleaner, but YMMV.
This commit is contained in:
parent
22570b7260
commit
8c3e864989
|
@ -2571,20 +2571,19 @@ void reload_config(WorkerProcess *wp) {
|
|||
// fork_worker_process and forked child process assumes new
|
||||
// configuration can be obtained from get_config().
|
||||
|
||||
auto old_config = replace_config(new_config.get());
|
||||
auto old_config = replace_config(std::move(new_config));
|
||||
|
||||
auto pid = fork_worker_process(ipc_fd, iaddrs);
|
||||
|
||||
if (pid == -1) {
|
||||
LOG(ERROR) << "Failed to process new configuration";
|
||||
|
||||
new_config = replace_config(std::move(old_config));
|
||||
close_not_inherited_fd(new_config.get(), iaddrs);
|
||||
replace_config(old_config);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
new_config.release();
|
||||
delete_config(old_config);
|
||||
|
||||
close_unused_inherited_addr(iaddrs);
|
||||
|
||||
// Send last worker process a graceful shutdown notice
|
||||
|
|
|
@ -60,41 +60,35 @@
|
|||
namespace shrpx {
|
||||
|
||||
namespace {
|
||||
Config *config = nullptr;
|
||||
std::unique_ptr<Config> config;
|
||||
} // namespace
|
||||
|
||||
constexpr auto SHRPX_UNIX_PATH_PREFIX = StringRef::from_lit("unix:");
|
||||
|
||||
const Config *get_config() { return config; }
|
||||
const Config *get_config() { return config.get(); }
|
||||
|
||||
Config *mod_config() { return config; }
|
||||
Config *mod_config() { return config.get(); }
|
||||
|
||||
Config *replace_config(Config *new_config) {
|
||||
std::swap(config, new_config);
|
||||
return new_config;
|
||||
std::unique_ptr<Config> replace_config(std::unique_ptr<Config> another) {
|
||||
config.swap(another);
|
||||
return another;
|
||||
}
|
||||
|
||||
void create_config() { config = new Config(); }
|
||||
void create_config() { config = make_unique<Config>(); }
|
||||
|
||||
void delete_config(Config *config) {
|
||||
if (config == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto &http2conf = config->http2;
|
||||
|
||||
auto &upstreamconf = http2conf.upstream;
|
||||
Config::~Config() {
|
||||
auto &upstreamconf = http2.upstream;
|
||||
|
||||
nghttp2_option_del(upstreamconf.option);
|
||||
nghttp2_option_del(upstreamconf.alt_mode_option);
|
||||
nghttp2_session_callbacks_del(upstreamconf.callbacks);
|
||||
|
||||
auto &downstreamconf = http2conf.downstream;
|
||||
auto &downstreamconf = http2.downstream;
|
||||
|
||||
nghttp2_option_del(downstreamconf.option);
|
||||
nghttp2_session_callbacks_del(downstreamconf.callbacks);
|
||||
|
||||
auto &dumpconf = http2conf.upstream.debug.dump;
|
||||
auto &dumpconf = http2.upstream.debug.dump;
|
||||
|
||||
if (dumpconf.request_header) {
|
||||
fclose(dumpconf.request_header);
|
||||
|
@ -103,8 +97,6 @@ void delete_config(Config *config) {
|
|||
if (dumpconf.response_header) {
|
||||
fclose(dumpconf.response_header);
|
||||
}
|
||||
|
||||
delete config;
|
||||
}
|
||||
|
||||
TicketKeys::~TicketKeys() {
|
||||
|
|
|
@ -706,6 +706,8 @@ struct APIConfig {
|
|||
};
|
||||
|
||||
struct Config {
|
||||
~Config();
|
||||
|
||||
HttpProxy downstream_http_proxy;
|
||||
HttpConfig http;
|
||||
Http2Config http2;
|
||||
|
@ -734,9 +736,8 @@ const Config *get_config();
|
|||
Config *mod_config();
|
||||
// Replaces the current config with given |new_config|. The old config is
|
||||
// returned.
|
||||
Config *replace_config(Config *new_config);
|
||||
std::unique_ptr<Config> replace_config(std::unique_ptr<Config> new_config);
|
||||
void create_config();
|
||||
void delete_config(Config *config);
|
||||
|
||||
// generated by gennghttpxfun.py
|
||||
enum {
|
||||
|
|
Loading…
Reference in New Issue