Break out sse into a compile unit
Verify similar to beb96b0 Break out websockets
Break out the SSE functions into a separate compile unit. This allows
the SSE sockets in beast to be compiled separately, which significantly
reduces the overall compile time by a few seconds. Code is identical
with the exceptions of minor header definitions to convert header-only
to compile unit.
Change-Id: I5aae4f17cbd2badf75b3e0bb644a2309f6300663
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/http/routing/sserule.cpp b/http/routing/sserule.cpp
new file mode 100644
index 0000000..2b71caf
--- /dev/null
+++ b/http/routing/sserule.cpp
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright OpenBMC Authors
+
+#include "sserule.hpp"
+
+#include "async_resp.hpp"
+#include "baserule.hpp"
+#include "http_request.hpp"
+#include "http_response.hpp"
+#include "logging.hpp"
+#include "server_sent_event_impl.hpp"
+
+#include <boost/asio/ip/tcp.hpp>
+#include <boost/asio/ssl/stream.hpp>
+#include <boost/beast/http/status.hpp>
+
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+namespace crow
+{
+
+SseSocketRule::SseSocketRule(const std::string& ruleIn) : BaseRule(ruleIn)
+{
+ isUpgrade = true;
+ // Clear GET handler
+ methodsBitfield = 0;
+}
+
+void SseSocketRule::validate() {}
+
+void SseSocketRule::handle(const Request& /*req*/,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::vector<std::string>& /*params*/)
+{
+ BMCWEB_LOG_ERROR(
+ "Handle called on websocket rule. This should never happen");
+ asyncResp->res.result(boost::beast::http::status::internal_server_error);
+}
+
+void SseSocketRule::handleUpgrade(
+ const Request& req, const std::shared_ptr<bmcweb::AsyncResp>& /*asyncResp*/,
+ boost::asio::ip::tcp::socket&& adaptor)
+{
+ std::shared_ptr<
+ crow::sse_socket::ConnectionImpl<boost::asio::ip::tcp::socket>>
+ myConnection = std::make_shared<
+ crow::sse_socket::ConnectionImpl<boost::asio::ip::tcp::socket>>(
+ std::move(adaptor), openHandler, closeHandler);
+ myConnection->start(req);
+}
+void SseSocketRule::handleUpgrade(
+ const Request& req, const std::shared_ptr<bmcweb::AsyncResp>& /*asyncResp*/,
+ boost::asio::ssl::stream<boost::asio::ip::tcp::socket>&& adaptor)
+{
+ std::shared_ptr<crow::sse_socket::ConnectionImpl<
+ boost::asio::ssl::stream<boost::asio::ip::tcp::socket>>>
+ myConnection = std::make_shared<crow::sse_socket::ConnectionImpl<
+ boost::asio::ssl::stream<boost::asio::ip::tcp::socket>>>(
+ std::move(adaptor), openHandler, closeHandler);
+ myConnection->start(req);
+}
+
+} // namespace crow