Remove getIoContext from Request object
At one point it was thought that we could pass the io_context object
through the request object, and have the potential to run multiple
io_context instances (one per connection).
Given the safety refactoring we had to do in
9838eb20341568971b9543c2187372d20daf64aa that idea is on ice for the
moment, and would need a major rethink of code to be viable. For the
moment, and in prep for
https://gerrit.openbmc.org/c/openbmc/bmcweb/+/75668
make sure all calls are pulling from the same io object.
Tested: Unit tests pass. Redfish service validator passes.
Change-Id: I877752005c4ce94efbc13ce815f3cd0d99cc3d51
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/http/server_sent_event.hpp b/http/server_sent_event.hpp
index a0105f1..31db6ff 100644
--- a/http/server_sent_event.hpp
+++ b/http/server_sent_event.hpp
@@ -4,11 +4,11 @@
#include "boost_formatters.hpp"
#include "http_body.hpp"
#include "http_request.hpp"
+#include "io_context_singleton.hpp"
#include "logging.hpp"
#include <boost/asio/buffer.hpp>
#include <boost/asio/error.hpp>
-#include <boost/asio/io_context.hpp>
#include <boost/asio/steady_timer.hpp>
#include <boost/beast/core/error.hpp>
#include <boost/beast/core/multi_buffer.hpp>
@@ -42,7 +42,6 @@
Connection& operator=(const Connection&&) = delete;
virtual ~Connection() = default;
- virtual boost::asio::io_context& getIoContext() = 0;
virtual void close(std::string_view msg = "quit") = 0;
virtual void sendSseEvent(std::string_view id, std::string_view msg) = 0;
};
@@ -55,9 +54,7 @@
Adaptor&& adaptorIn,
std::function<void(Connection&, const Request&)> openHandlerIn,
std::function<void(Connection&)> closeHandlerIn) :
- adaptor(std::move(adaptorIn)),
- timer(static_cast<boost::asio::io_context&>(
- adaptor.get_executor().context())),
+ adaptor(std::move(adaptorIn)), timer(getIoContext()),
openHandler(std::move(openHandlerIn)),
closeHandler(std::move(closeHandlerIn))
@@ -75,12 +72,6 @@
BMCWEB_LOG_DEBUG("SSE ConnectionImpl: SSE destructor {}", logPtr(this));
}
- boost::asio::io_context& getIoContext() override
- {
- return static_cast<boost::asio::io_context&>(
- adaptor.get_executor().context());
- }
-
void start(const Request& req)
{
BMCWEB_LOG_DEBUG("Starting SSE connection");