0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 08:12:37 +01:00

ircd::net: Add translate/reflect for disconnect type.

This commit is contained in:
Jason Volk 2023-03-20 13:30:43 -07:00
parent b3832541ff
commit 6d73a65867
2 changed files with 50 additions and 9 deletions

View file

@ -17,6 +17,8 @@ namespace ircd::net
struct close_opts extern const close_opts_default;
using close_callback = std::function<void (std::exception_ptr)>;
string_view reflect(const dc) noexcept;
// Callback-based closer.
void close(socket &, const close_opts &, close_callback);
void close(socket &, const dc &, close_callback);

View file

@ -672,6 +672,11 @@ ircd::net::reflect(const ready &type)
// net/close.h
//
namespace ircd::net
{
static asio::ip::tcp::socket::shutdown_type translate(const dc &) noexcept;
}
decltype(ircd::net::close_opts::default_timeout)
ircd::net::close_opts::default_timeout
{
@ -742,6 +747,46 @@ ircd::net::close(socket &socket,
socket.disconnect(opts, std::move(callback));
}
boost::asio::ip::tcp::socket::shutdown_type
ircd::net::translate(const dc &val)
noexcept
{
using type = asio::ip::tcp::socket::shutdown_type;
switch(val)
{
case dc::SSL_NOTIFY: assert(0); [[fallthrough]];
case dc::RST: assert(0); [[fallthrough]];
case dc::FIN:
return type::shutdown_both;
case dc::FIN_SEND:
return type::shutdown_send;
case dc::FIN_RECV:
return type::shutdown_receive;
}
assert(0);
__builtin_unreachable();
}
ircd::string_view
ircd::net::reflect(const dc type)
noexcept
{
switch(type)
{
case dc::RST: return "RST";
case dc::FIN: return "FIN";
case dc::FIN_SEND: return "FIN_SEND";
case dc::FIN_RECV: return "FIN_RECV";
case dc::SSL_NOTIFY: return "SSL_NOTIFY";
}
return "????"_sv;
}
///////////////////////////////////////////////////////////////////////////////
//
// net/open.h
@ -1730,9 +1775,9 @@ try
assert(!fini);
log::debug
{
log, "%s disconnect type:%d user: in:%zu out:%zu",
log, "%s disconnect type:%s user[in:%zu out:%zu]",
loghead(*this),
uint(opts.type),
reflect(opts.type),
in.bytes,
out.bytes
};
@ -1751,15 +1796,9 @@ try
break;
case dc::FIN:
sd.shutdown(ip::tcp::socket::shutdown_both);
break;
case dc::FIN_SEND:
sd.shutdown(ip::tcp::socket::shutdown_send);
break;
case dc::FIN_RECV:
sd.shutdown(ip::tcp::socket::shutdown_receive);
sd.shutdown(translate(opts.type));
break;
case dc::SSL_NOTIFY: