From a32210a64d9f839ad4b469daa168f64dbf8f89b6 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 23 Aug 2017 15:49:33 -0600 Subject: [PATCH] ircd: Support proper socket disconnect for SSL. --- include/ircd/socket.h | 12 +++++++----- ircd/socket.cc | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/include/ircd/socket.h b/include/ircd/socket.h index 5aa776bca..f9ab33eba 100644 --- a/include/ircd/socket.h +++ b/include/ircd/socket.h @@ -58,10 +58,12 @@ struct socket enum dc { - RST, // hardest disconnect - FIN, // graceful shutdown both directions - FIN_SEND, // graceful shutdown send side - FIN_RECV, // graceful shutdown recv side + RST, // hardest disconnect + FIN, // graceful shutdown both directions + FIN_SEND, // graceful shutdown send side + FIN_RECV, // graceful shutdown recv side + SSL_NOTIFY, // SSL close_notify (async, errors ignored) + SSL_NOTIFY_YIELD, // SSL close_notify (yields context, throws) }; struct stat @@ -111,7 +113,7 @@ struct socket void operator()(handler); void cancel(); - void disconnect(const dc &type = dc::FIN); + void disconnect(const dc &type = dc::SSL_NOTIFY); void connect(const ip::tcp::endpoint &ep, const milliseconds &timeout = -1ms); socket(const std::string &host, diff --git a/ircd/socket.cc b/ircd/socket.cc index 7f4b137d7..2e09738ae 100644 --- a/ircd/socket.cc +++ b/ircd/socket.cc @@ -175,6 +175,29 @@ ircd::socket::disconnect(const dc &type) 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); break; + + case dc::SSL_NOTIFY: + { + ssl.async_shutdown([socket(shared_from_this())] + (boost::system::error_code ec) + { + if(!ec) + socket->sd.close(ec); + + if(ec) + log::warning("socket(%p): disconnect(): %s", + socket.get(), + ec.message()); + }); + break; + } + + case dc::SSL_NOTIFY_YIELD: + { + ssl.async_shutdown(yield(continuation())); + sd.close(); + break; + } } }