From 58780d9e3d999dcb8178a38354fef58b5fd4b09b Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Fri, 15 Dec 2023 09:38:44 -0500 Subject: [PATCH] cover more potential exception states withn the REST service; --- src/network/rest/http/ClientConnection.h | 26 ++++++++++++++++++------ src/network/rest/http/ServerConnection.h | 10 ++++++--- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/network/rest/http/ClientConnection.h b/src/network/rest/http/ClientConnection.h index a4f790d2..05ede2e4 100644 --- a/src/network/rest/http/ClientConnection.h +++ b/src/network/rest/http/ClientConnection.h @@ -95,9 +95,19 @@ namespace network /// Helper to enable the SO_LINGER socket option during shutdown. void ensureNoLinger() { - // enable SO_LINGER timeout 0 - asio::socket_base::linger linger(true, 0); - m_socket.set_option(linger); + try + { + // enable SO_LINGER timeout 0 + asio::socket_base::linger linger(true, 0); + m_socket.set_option(linger); + } + catch(const asio::system_error& e) + { + asio::error_code ec = e.code(); + if (ec) { + ::LogError(LOG_REST, "%s, code = %u", ec.message().c_str(), ec.value()); + } + } } /// Perform an synchronous write operation. @@ -158,9 +168,13 @@ namespace network if (ec) { ::LogError(LOG_REST, "%s, code = %u", ec.message().c_str(), ec.value()); - // initiate graceful connection closure - asio::error_code ignored_ec; - m_socket.shutdown(asio::ip::tcp::socket::shutdown_both, ignored_ec); + try + { + // initiate graceful connection closure + asio::error_code ignored_ec; + m_socket.shutdown(asio::ip::tcp::socket::shutdown_both, ignored_ec); + } + catch(const std::exception& e) { ::LogError(LOG_REST, "%s", ec.message().c_str()); } } } } diff --git a/src/network/rest/http/ServerConnection.h b/src/network/rest/http/ServerConnection.h index 0daef7b9..107efca5 100644 --- a/src/network/rest/http/ServerConnection.h +++ b/src/network/rest/http/ServerConnection.h @@ -168,9 +168,13 @@ namespace network } else { if (!ec) { - // initiate graceful connection closure - asio::error_code ignored_ec; - m_socket.shutdown(asio::ip::tcp::socket::shutdown_both, ignored_ec); + try + { + // initiate graceful connection closure + asio::error_code ignored_ec; + m_socket.shutdown(asio::ip::tcp::socket::shutdown_both, ignored_ec); + } + catch(const std::exception& e) { ::LogError(LOG_REST, "%s", ec.message().c_str()); } } if (ec != asio::error::operation_aborted) {