shutting down socket before closing the connection

This commit is contained in:
The-EDev 2020-10-20 11:48:35 +03:00
parent 745f6c95c6
commit 63ea212e1a
2 changed files with 39 additions and 0 deletions

View File

@ -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;

View File

@ -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 <typename F>
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());