From ab17b0264caf3d803fade94080a0e9a02d5c9f24 Mon Sep 17 00:00:00 2001 From: deniskovalchuk Date: Tue, 16 Apr 2024 02:27:52 +0300 Subject: [PATCH] core: perform shutdown before closing in control_connection::recv() --- src/control_connection.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/control_connection.cpp b/src/control_connection.cpp index 68170e4..fbe7e6c 100644 --- a/src/control_connection.cpp +++ b/src/control_connection.cpp @@ -183,6 +183,33 @@ reply control_connection::recv() { boost::system::error_code ec; + if (socket_->has_ssl_support()) + { + socket_->ssl_shutdown(ec); + } + else + { + socket_->shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec); + } + + if (ec == boost::asio::error::not_connected) + { + /* Ignore 'not_connected' error. We could get ENOTCONN if a server side + * has already closed the control connection. This suits us, just close + * the socket. + */ + } + else if (ec == boost::asio::error::eof) + { + /* Rationale: + * http://stackoverflow.com/questions/25587403/boost-asio-ssl-async-shutdown-always-finishes-with-an-error + */ + } + else if (ec) + { + throw ftp_exception(ec, "Cannot close control connection"); + } + socket_->close(ec); if (ec)