From 93cf0ac2c7921d3344fa112f667c47a838e3b7d6 Mon Sep 17 00:00:00 2001 From: Ed Tanous Date: Thu, 28 Mar 2024 00:35:13 -0700 Subject: Fix SSE sockets Redfish protocol validatator has SSE tests that expose some bad coding practies in SSE handlers, namely, that there are several cases where we don't check for nullptr. Fix them. This appears to have been introduced in: https://gerrit.openbmc.org/c/openbmc/bmcweb/+/41319 Tested: Redfish service validator passes more tests. Change-Id: Id980725f007d044b7d120dbe0f4b625865cab6ba Signed-off-by: Ed Tanous --- http/routing/sserule.hpp | 8 ++++---- http/server_sent_event.hpp | 9 +++++---- 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'http') diff --git a/http/routing/sserule.hpp b/http/routing/sserule.hpp index 1a422a8268..c0a4e504b3 100644 --- a/http/routing/sserule.hpp +++ b/http/routing/sserule.hpp @@ -31,7 +31,7 @@ class SseSocketRule : public BaseRule } #ifndef BMCWEB_ENABLE_SSL - void handleUpgrade(const Request& req, + void handleUpgrade(const Request& /*req*/, const std::shared_ptr& /*asyncResp*/, boost::asio::ip::tcp::socket&& adaptor) override { @@ -39,11 +39,11 @@ class SseSocketRule : public BaseRule crow::sse_socket::ConnectionImpl> myConnection = std::make_shared< crow::sse_socket::ConnectionImpl>( - *req.ioService, std::move(adaptor), openHandler, closeHandler); + std::move(adaptor), openHandler, closeHandler); myConnection->start(); } #else - void handleUpgrade(const Request& req, + void handleUpgrade(const Request& /*req*/, const std::shared_ptr& /*asyncResp*/, boost::beast::ssl_stream&& adaptor) override @@ -52,7 +52,7 @@ class SseSocketRule : public BaseRule boost::beast::ssl_stream>> myConnection = std::make_shared>>( - *req.ioService, std::move(adaptor), openHandler, closeHandler); + std::move(adaptor), openHandler, closeHandler); myConnection->start(); } #endif diff --git a/http/server_sent_event.hpp b/http/server_sent_event.hpp index a8bccdb450..0e1cd62a9d 100644 --- a/http/server_sent_event.hpp +++ b/http/server_sent_event.hpp @@ -18,7 +18,7 @@ namespace crow namespace sse_socket { -struct Connection : std::enable_shared_from_this +struct Connection : public std::enable_shared_from_this { public: Connection() = default; @@ -38,11 +38,13 @@ template class ConnectionImpl : public Connection { public: - ConnectionImpl(boost::asio::io_context& ioIn, Adaptor&& adaptorIn, + ConnectionImpl(Adaptor&& adaptorIn, std::function openHandlerIn, std::function closeHandlerIn) : adaptor(std::move(adaptorIn)), - ioc(ioIn), timer(ioc), openHandler(std::move(openHandlerIn)), + timer(static_cast( + adaptor.get_executor().context())), + openHandler(std::move(openHandlerIn)), closeHandler(std::move(closeHandlerIn)) { @@ -276,7 +278,6 @@ class ConnectionImpl : public Connection using BodyType = bmcweb::HttpBody; boost::beast::http::response res; std::optional> serializer; - boost::asio::io_context& ioc; boost::asio::steady_timer timer; bool doingWrite = false; -- cgit v1.2.3