mirror of
https://github.com/matrix-construct/construct
synced 2024-06-08 04:58:58 +02:00
ircd::net: Allow designated and implicit constructions for close_opts.
This commit is contained in:
parent
14f55f6110
commit
b3832541ff
|
@ -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<void> close(const net::close_opts & = {});
|
||||
void close(const net::dc, net::close_callback);
|
||||
ctx::future<void> close(const net::close_opts &);
|
||||
ctx::future<void> close(const net::dc);
|
||||
|
||||
private:
|
||||
void discard_unconsumed(const http::request::head &);
|
||||
|
|
|
@ -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<void> close(socket &, const close_opts & = close_opts_default);
|
||||
ctx::future<void> 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<milliseconds> 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}
|
||||
{}
|
||||
|
|
|
@ -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 &);
|
||||
|
|
|
@ -1048,6 +1048,15 @@ ircd::client::discard_unconsumed(const http::request::head &head)
|
|||
assert(content_consumed == head.content_length);
|
||||
}
|
||||
|
||||
ircd::ctx::future<void>
|
||||
ircd::client::close(const net::dc type)
|
||||
{
|
||||
return close(net::close_opts
|
||||
{
|
||||
.type = type,
|
||||
});
|
||||
}
|
||||
|
||||
ircd::ctx::future<void>
|
||||
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)
|
||||
|
|
29
ircd/net.cc
29
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<void>
|
||||
ircd::net::close(socket &s,
|
||||
const dc &type)
|
||||
{
|
||||
return close(s, close_opts
|
||||
{
|
||||
.type = type,
|
||||
});
|
||||
}
|
||||
|
||||
ircd::ctx::future<void>
|
||||
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,
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue