From b3832541ff8e4eea23fb6aac053b159e5cb66316 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 20 Mar 2023 13:28:16 -0700 Subject: [PATCH] ircd::net: Allow designated and implicit constructions for close_opts. --- include/ircd/client.h | 4 +++- include/ircd/net/close.h | 12 ++---------- include/ircd/server/link.h | 3 ++- ircd/client.cc | 21 +++++++++++++++++++++ ircd/net.cc | 29 +++++++++++++++++++++++++---- ircd/server.cc | 9 +++++++++ 6 files changed, 62 insertions(+), 16 deletions(-) diff --git a/include/ircd/client.h b/include/ircd/client.h index b816ca714..450422417 100644 --- a/include/ircd/client.h +++ b/include/ircd/client.h @@ -56,7 +56,9 @@ struct ircd::client size_t write_all(const net::const_buffers &); size_t write_all(const const_buffer &); void close(const net::close_opts &, net::close_callback); - ctx::future close(const net::close_opts & = {}); + void close(const net::dc, net::close_callback); + ctx::future close(const net::close_opts &); + ctx::future close(const net::dc); private: void discard_unconsumed(const http::request::head &); diff --git a/include/ircd/net/close.h b/include/ircd/net/close.h index 314073007..db3daf973 100644 --- a/include/ircd/net/close.h +++ b/include/ircd/net/close.h @@ -19,9 +19,11 @@ namespace ircd::net // Callback-based closer. void close(socket &, const close_opts &, close_callback); + void close(socket &, const dc &, close_callback); // Future-based closer. ctx::future close(socket &, const close_opts & = close_opts_default); + ctx::future close(socket &, const dc &); // Fire-and-forget helper callback for close(). extern const close_callback close_ignore; @@ -44,9 +46,6 @@ struct ircd::net::close_opts { static conf::item default_timeout; - close_opts() = default; - close_opts(const net::dc &); - /// The type of close() to be conducted is specified here. net::dc type { dc::SSL_NOTIFY }; @@ -57,10 +56,3 @@ struct ircd::net::close_opts /// the disconnect (useful for adding an SO_LINGER time etc). const sock_opts *sopts { nullptr }; }; - -/// Allows for implicit construction of close_opts in arguments to close() -/// without requiring brackets for the close_opts& argument. -inline -ircd::net::close_opts::close_opts(const net::dc &type) -:type{type} -{} diff --git a/include/ircd/server/link.h b/include/ircd/server/link.h index 12c61ab49..6ef9ac23b 100644 --- a/include/ircd/server/link.h +++ b/include/ircd/server/link.h @@ -93,7 +93,8 @@ struct ircd::server::link void submit(request &); // control panel - bool close(const net::close_opts & = net::close_opts_default); + bool close(const net::close_opts &); + bool close(const net::dc = net::dc::SSL_NOTIFY); bool open(const net::open_opts &); link(server::peer &); diff --git a/ircd/client.cc b/ircd/client.cc index dbf93d776..35baa86b3 100644 --- a/ircd/client.cc +++ b/ircd/client.cc @@ -1048,6 +1048,15 @@ ircd::client::discard_unconsumed(const http::request::head &head) assert(content_consumed == head.content_length); } +ircd::ctx::future +ircd::client::close(const net::dc type) +{ + return close(net::close_opts + { + .type = type, + }); +} + ircd::ctx::future ircd::client::close(const net::close_opts &opts) { @@ -1056,6 +1065,18 @@ ircd::client::close(const net::close_opts &opts) ctx::already; } +void +ircd::client::close(const net::dc type, + net::close_callback callback) +{ + const net::close_opts opts + { + .type = type, + }; + + close(opts, std::move(callback)); +} + void ircd::client::close(const net::close_opts &opts, net::close_callback callback) diff --git a/ircd/net.cc b/ircd/net.cc index dc2780697..b1f48ae8f 100644 --- a/ircd/net.cc +++ b/ircd/net.cc @@ -680,10 +680,8 @@ ircd::net::close_opts::default_timeout }; /// Static instance of default close options. -ircd::net::close_opts -const ircd::net::close_opts_default -{ -}; +decltype(ircd::net::close_opts_default) +ircd::net::close_opts_default; /// Static helper callback which may be passed to the callback-based overload /// of close(). This callback does nothing. @@ -694,6 +692,16 @@ const ircd::net::close_ignore{[] return; }}; +ircd::ctx::future +ircd::net::close(socket &s, + const dc &type) +{ + return close(s, close_opts + { + .type = type, + }); +} + ircd::ctx::future ircd::net::close(socket &socket, const close_opts &opts) @@ -713,6 +721,19 @@ ircd::net::close(socket &socket, return f; } +void +ircd::net::close(socket &s, + const dc &type, + close_callback cb) +{ + const close_opts opts + { + .type = type, + }; + + return close(s, opts, std::move(cb)); +} + void ircd::net::close(socket &socket, const close_opts &opts, diff --git a/ircd/server.cc b/ircd/server.cc index 8914e8806..80332efb2 100644 --- a/ircd/server.cc +++ b/ircd/server.cc @@ -2424,6 +2424,15 @@ ircd::server::link::handle_open(std::exception_ptr eptr) peer->handle_open(*this, std::move(eptr)); } +bool +ircd::server::link::close(const net::dc type) +{ + return close(net::close_opts + { + .type = type, + }); +} + bool ircd::server::link::close(const net::close_opts &close_opts) {