From 52b1b7ead32a3529ce54d2f2e4df3201a494e436 Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Fri, 26 Aug 2022 16:32:39 +0200 Subject: [PATCH] Avoid repeatedly calling `stream->lowest_layer()` within the same scope & move some variable constructions --- lib/remote/httpserverconnection.cpp | 9 +++------ lib/remote/jsonrpcconnection.cpp | 5 +++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/remote/httpserverconnection.cpp b/lib/remote/httpserverconnection.cpp index c07c19a38..df1b57a99 100644 --- a/lib/remote/httpserverconnection.cpp +++ b/lib/remote/httpserverconnection.cpp @@ -92,11 +92,12 @@ void HttpServerConnection::Disconnect() m_CheckLivenessTimer.cancel(); - m_Stream->lowest_layer().cancel(ec); + auto& lowestLayer = m_Stream->lowest_layer(); + lowestLayer.cancel(ec); m_Stream->next_layer().async_shutdown(yc[ec]); - m_Stream->lowest_layer().shutdown(m_Stream->lowest_layer().shutdown_both, ec); + lowestLayer.shutdown(lowestLayer.shutdown_both, ec); auto listener (ApiListener::GetInstance()); @@ -239,8 +240,6 @@ bool HandleAccessControl( auto headerAllowOrigin (listener->GetAccessControlAllowOrigin()); if (headerAllowOrigin) { - CpuBoundWork allowOriginHeader (yc); - auto allowedOrigins (headerAllowOrigin->ToSet()); if (!allowedOrigins.empty()) { @@ -250,8 +249,6 @@ bool HandleAccessControl( response.set(http::field::access_control_allow_origin, origin); } - allowOriginHeader.Done(); - response.set(http::field::access_control_allow_credentials, "true"); if (request.method() == http::verb::options && !request[http::field::access_control_request_method].empty()) { diff --git a/lib/remote/jsonrpcconnection.cpp b/lib/remote/jsonrpcconnection.cpp index 3bae3cafd..54297814f 100644 --- a/lib/remote/jsonrpcconnection.cpp +++ b/lib/remote/jsonrpcconnection.cpp @@ -226,7 +226,8 @@ void JsonRpcConnection::Disconnect() m_CheckLivenessTimer.cancel(); m_HeartbeatTimer.cancel(); - m_Stream->lowest_layer().cancel(ec); + auto& lowestLayer = m_Stream->lowest_layer(); + lowestLayer.cancel(ec); Timeout::Ptr shutdownTimeout (new Timeout( m_IoStrand.context(), @@ -242,7 +243,7 @@ void JsonRpcConnection::Disconnect() shutdownTimeout->Cancel(); - m_Stream->lowest_layer().shutdown(m_Stream->lowest_layer().shutdown_both, ec); + lowestLayer.shutdown(lowestLayer.shutdown_both, ec); } }); }