Skip to content

Commit

Permalink
GH-1662 Remove do_eof() as not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Oct 2, 2023
1 parent 17110a1 commit 4f4f5d3
Showing 1 changed file with 6 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class beast_http_session : public detail::abstract_conn,
if(ec) {
// See on_read comment below
if(ec == http::error::end_of_stream || ec == asio::error::connection_reset)
return do_eof();
return; // socket destructor will be called

return fail(ec, "read_header", plugin_state_.get_logger(), "closing connection");
}
Expand Down Expand Up @@ -337,7 +337,7 @@ class beast_http_session : public detail::abstract_conn,
// on another read. If the client disconnects, we may get
// http::error::end_of_stream or asio::error::connection_reset.
if(ec == http::error::end_of_stream || ec == asio::error::connection_reset)
return do_eof();
return; // socket destructor will be called

return fail(ec, "read", plugin_state_.get_logger(), "closing connection");
}
Expand Down Expand Up @@ -367,7 +367,7 @@ class beast_http_session : public detail::abstract_conn,
if(close) {
// This means we should close the connection, usually because
// the response indicated the "Connection: close" semantic.
return do_eof();
return; // socket destructor will be called
}

// create a new response object
Expand All @@ -383,7 +383,7 @@ class beast_http_session : public detail::abstract_conn,
case continue_state_t::reject:
// request body too large. After issuing 401 response, close connection
continue_state_ = continue_state_t::none;
do_eof();
// socket destructor will be called
break;

default:
Expand Down Expand Up @@ -450,7 +450,7 @@ class beast_http_session : public detail::abstract_conn,
res_->set(http::field::server, BOOST_BEAST_VERSION_STRING);

send_response(std::move(err_str), static_cast<unsigned int>(http::status::internal_server_error));
do_eof();
// socket destructor will be called
}
}

Expand Down Expand Up @@ -492,26 +492,12 @@ class beast_http_session : public detail::abstract_conn,
void run_session() {
if(auto error_str = verify_max_requests_in_flight(); !error_str.empty()) {
send_busy_response(std::move(error_str));
return do_eof();
return; // socket destructor will be called
}

do_read_header();
}

void do_eof() {
is_send_exception_response_ = false;
try {
// Send a shutdown signal
beast::error_code ec;
socket_.shutdown(Socket::shutdown_both, ec);
socket_.close(ec);
// At this point the connection is closed gracefully
} catch(...) {
handle_exception();
}
}


bool allow_host(const http::request<http::string_body>& req) {
if constexpr(std::is_same_v<Socket, tcp::socket>) {
const std::string host_str(req["host"]);
Expand Down

0 comments on commit 4f4f5d3

Please sign in to comment.