Skip to content

Commit

Permalink
core: perform shutdown before closing in control_connection::recv()
Browse files Browse the repository at this point in the history
  • Loading branch information
deniskovalchuk committed Apr 15, 2024
1 parent af293f3 commit ab17b02
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/control_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ab17b02

Please sign in to comment.