ircd::net: Add close option to skip shutdown syscall prior to close.

This commit is contained in:
Jason Volk 2023-03-20 13:32:36 -07:00
parent 6d73a65867
commit 575211d37e
3 changed files with 18 additions and 3 deletions

View File

@ -57,4 +57,10 @@ struct ircd::net::close_opts
/// If specified, these socket options will be applied when conducting
/// the disconnect (useful for adding an SO_LINGER time etc).
const sock_opts *sopts { nullptr };
/// For portable clean disconnection shutdown(2) might be called prior to
/// close(2). Setting this option to dc::RST skips the shutdown(2) when
/// the caller deems it unnecessary. At this time it only affects non-SSL
/// sockets and in the future we will have io_uring(7) fuse these calls.
net::dc shutdown { dc::FIN };
};

View File

@ -587,7 +587,13 @@ try
loghead(client),
};
client.close(net::dc::SSL_NOTIFY, net::close_ignore);
const net::close_opts opts
{
.type = net::dc::SSL_NOTIFY,
.shutdown = net::dc::RST,
};
client.close(opts, net::close_ignore);
return false;
}
catch(const std::exception &e)

View File

@ -1775,9 +1775,10 @@ try
assert(!fini);
log::debug
{
log, "%s disconnect type:%s user[in:%zu out:%zu]",
log, "%s disconnect type:%s shut:%s user[in:%zu out:%zu]",
loghead(*this),
reflect(opts.type),
!ssl? reflect(opts.shutdown): "--"_sv,
in.bytes,
out.bytes
};
@ -1806,7 +1807,9 @@ try
if(!ssl)
{
// Redirect SSL_NOTIFY to another strategy for non-SSL sockets.
sd.shutdown(ip::tcp::socket::shutdown_both);
if(opts.shutdown != dc::RST)
sd.shutdown(translate(opts.shutdown));
sd.close();
break;
}