From 1c5fadd56944c3aedefaf6065bbce4a028e620e4 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Tue, 5 Mar 2024 14:06:13 +0100 Subject: some asio HTTP server tweaks for correctness (#663) --- src/zenhttp/servers/httpasio.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/zenhttp/servers/httpasio.cpp b/src/zenhttp/servers/httpasio.cpp index 6b45c259d..c75057733 100644 --- a/src/zenhttp/servers/httpasio.cpp +++ b/src/zenhttp/servers/httpasio.cpp @@ -293,7 +293,7 @@ HttpServerConnection::TerminateConnection() void HttpServerConnection::EnqueueRead() { - if (m_RequestState == RequestState::kInitialRead) + if ((m_RequestState == RequestState::kInitialRead) || (m_RequestState == RequestState::kReadingMore)) { m_RequestState = RequestState::kReadingMore; } @@ -315,15 +315,17 @@ HttpServerConnection::OnDataReceived(const asio::error_code& Ec, [[maybe_unused] { if (Ec) { - if (m_RequestState == RequestState::kDone || m_RequestState == RequestState::kInitialRead) + switch (m_RequestState) { - ZEN_TRACE_VERBOSE("on data received ERROR (EXPECTED), connection: {}, reason: '{}'", m_ConnectionId, Ec.message()); - return; - } - else - { - ZEN_WARN("on data received ERROR, connection: {}, reason '{}'", m_ConnectionId, Ec.message()); - return TerminateConnection(); + case RequestState::kDone: + case RequestState::kInitialRead: + case RequestState::kTerminated: + ZEN_TRACE_VERBOSE("on data received ERROR (EXPECTED), connection: {}, reason: '{}'", m_ConnectionId, Ec.message()); + return; + + default: + ZEN_WARN("on data received ERROR, connection: {}, reason '{}'", m_ConnectionId, Ec.message()); + return TerminateConnection(); } } -- cgit v1.2.3