Break out websockets
When running clang build analyzer it shows that one of the largest
templates in the Redfish compile unit (which is also the slowest compile
unit) is actually the beast websocket instantiations, taking about 6
seconds to compile on their own.
Luckily, the websocket layer is already split into Websocket and
WebsocketImpl classes that we inherited from crow. Unfortunately, crow
puts these two classes into the same file. So.
1. Move the WebSocketImpl class into its own header.
2. Move the websocket() upgrade routes in the websocket routing rule
into their own compile unit to take advantage of only needing
WebsocketImpl in this compile unit.
Tested: Drops build time by several seconds depending on what other
level of optimizations are present (1:15 -> 1:00)
[1] https://github.com/aras-p/ClangBuildAnalyzer
Change-Id: Ia0445eae4a793bb4ccb28136f30d2a05662c529c
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/http/routing/websocketrule.cpp b/http/routing/websocketrule.cpp
new file mode 100644
index 0000000..898a1d0
--- /dev/null
+++ b/http/routing/websocketrule.cpp
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright OpenBMC Authors
+
+#include "websocketrule.hpp"
+
+#include "async_resp.hpp"
+#include "http_request.hpp"
+#include "logging.hpp"
+#include "websocket_impl.hpp"
+
+#include <boost/asio/ip/tcp.hpp>
+#include <boost/asio/ssl/stream.hpp>
+
+#include <memory>
+#include <utility>
+
+namespace crow
+{
+void WebSocketRule::handleUpgrade(
+ const Request& req, const std::shared_ptr<bmcweb::AsyncResp>& /*asyncResp*/,
+ boost::asio::ip::tcp::socket&& adaptor)
+{
+ BMCWEB_LOG_DEBUG("Websocket handles upgrade");
+ std::shared_ptr<
+ crow::websocket::ConnectionImpl<boost::asio::ip::tcp::socket>>
+ myConnection = std::make_shared<
+ crow::websocket::ConnectionImpl<boost::asio::ip::tcp::socket>>(
+ req.url(), req.session, std::move(adaptor), openHandler,
+ messageHandler, messageExHandler, closeHandler, errorHandler);
+ myConnection->start(req);
+}
+
+void WebSocketRule::handleUpgrade(
+ const Request& req, const std::shared_ptr<bmcweb::AsyncResp>& /*asyncResp*/,
+ boost::asio::ssl::stream<boost::asio::ip::tcp::socket>&& adaptor)
+{
+ BMCWEB_LOG_DEBUG("Websocket handles upgrade");
+ std::shared_ptr<crow::websocket::ConnectionImpl<
+ boost::asio::ssl::stream<boost::asio::ip::tcp::socket>>>
+ myConnection = std::make_shared<crow::websocket::ConnectionImpl<
+ boost::asio::ssl::stream<boost::asio::ip::tcp::socket>>>(
+ req.url(), req.session, std::move(adaptor), openHandler,
+ messageHandler, messageExHandler, closeHandler, errorHandler);
+ myConnection->start(req);
+}
+} // namespace crow