From 63ea212e1ae8c01a7d6d6ae1fefa9c98277d313a Mon Sep 17 00:00:00 2001 From: The-EDev Date: Tue, 20 Oct 2020 11:48:35 +0300 Subject: [PATCH] shutting down socket before closing the connection --- include/crow/http_connection.h | 3 +++ include/crow/socket_adaptors.h | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/crow/http_connection.h b/include/crow/http_connection.h index 2b92f01a4..2fc3bf0be 100644 --- a/include/crow/http_connection.h +++ b/include/crow/http_connection.h @@ -518,6 +518,7 @@ namespace crow { cancel_deadline_timer(); parser_.done(); + adaptor_.shutdown_read(); adaptor_.close(); is_reading = false; CROW_LOG_DEBUG << this << " from read(1)"; @@ -558,6 +559,7 @@ namespace crow { if (close_connection_) { + adaptor_.shutdown_write(); adaptor_.close(); CROW_LOG_DEBUG << this << " from write(1)"; check_destroy(); @@ -597,6 +599,7 @@ namespace crow { return; } + adaptor_.shutdown_readwrite(); adaptor_.close(); }); CROW_LOG_DEBUG << this << " timer added: " << timer_cancel_key_.first << ' ' << timer_cancel_key_.second; diff --git a/include/crow/socket_adaptors.h b/include/crow/socket_adaptors.h index 4bbc35c64..a3df1de2b 100644 --- a/include/crow/socket_adaptors.h +++ b/include/crow/socket_adaptors.h @@ -53,6 +53,24 @@ namespace crow socket_.close(ec); } + void shutdown_readwrite() + { + boost::system::error_code ec; + socket_.shutdown(boost::asio::socket_base::shutdown_type::shutdown_both, ec); + } + + void shutdown_write() + { + boost::system::error_code ec; + socket_.shutdown(boost::asio::socket_base::shutdown_type::shutdown_send, ec); + } + + void shutdown_read() + { + boost::system::error_code ec; + socket_.shutdown(boost::asio::socket_base::shutdown_type::shutdown_receive, ec); + } + template void start(F f) { @@ -99,6 +117,24 @@ namespace crow raw_socket().close(ec); } + void shutdown_readwrite() + { + boost::system::error_code ec; + raw_socket().shutdown(boost::asio::socket_base::shutdown_type::shutdown_both, ec); + } + + void shutdown_write() + { + boost::system::error_code ec; + raw_socket().shutdown(boost::asio::socket_base::shutdown_type::shutdown_send, ec); + } + + void shutdown_read() + { + boost::system::error_code ec; + raw_socket().shutdown(boost::asio::socket_base::shutdown_type::shutdown_receive, ec); + } + boost::asio::io_service& get_io_service() { return GET_IO_SERVICE(raw_socket());