summaryrefslogtreecommitdiffstats
path: root/http/websocket.h
diff options
context:
space:
mode:
authorJan Sowinski <jan.sowinski@intel.com>2019-12-03 10:37:06 +0100
committerJan Sowinski <jan.sowinski@intel.com>2019-12-19 13:01:38 +0000
commitc00500bcb9c5145f5cacb78bbe3dd694fb85ba0a (patch)
tree0aa8d2616be800b68fe7091e3e67b50f7b3326c9 /http/websocket.h
parentcac94c55c59a397524a04786f4d699e2bd7f21bf (diff)
downloadbmcweb-c00500bcb9c5145f5cacb78bbe3dd694fb85ba0a.tar.gz
bmcweb-c00500bcb9c5145f5cacb78bbe3dd694fb85ba0a.zip
Connection and websockets fixes
This commit fixes issue around Connection class and websockets - controlling connection lifetime by shared_ptr instead of manual new/delete - fixed memory leak when upgrading connection to websockets - removed dangling reference to conn.req in websockets - fixed lack of reponse for invalid websockets URLs - fixed not working connections deadline timer There is no noticable performance impact after switching connection management to shared pointers. Benchmark results using: wrk https://${bmc} shared_ptr: 144.29 Requests/sec new/delete: 144.41 Requests/sec Tested manually: performance: wrk https://${bmc} memory leaks: top websockets: webui- KVM and VirtualMedia HTTP GET on random Redfish schemas: postman Signed-off-by: Jan Sowinski <jan.sowinski@intel.com> Change-Id: I63f7395ba081a68e7900eae2ed204acd50f58689
Diffstat (limited to 'http/websocket.h')
-rw-r--r--http/websocket.h15
1 files changed, 7 insertions, 8 deletions
diff --git a/http/websocket.h b/http/websocket.h
index 80d536a..f7c818e 100644
--- a/http/websocket.h
+++ b/http/websocket.h
@@ -20,8 +20,8 @@ namespace websocket
struct Connection : std::enable_shared_from_this<Connection>
{
public:
- explicit Connection(const crow::Request& reqIn, crow::Response& res) :
- req(reqIn), userdataPtr(nullptr){};
+ explicit Connection(const crow::Request& reqIn) :
+ req(reqIn.req), userdataPtr(nullptr){};
virtual void sendBinary(const std::string_view msg) = 0;
virtual void sendBinary(std::string&& msg) = 0;
@@ -40,7 +40,7 @@ struct Connection : std::enable_shared_from_this<Connection>
return userdataPtr;
}
- crow::Request req;
+ boost::beast::http::request<boost::beast::http::string_body> req;
crow::Response res;
private:
@@ -51,14 +51,14 @@ template <typename Adaptor> class ConnectionImpl : public Connection
{
public:
ConnectionImpl(
- const crow::Request& reqIn, crow::Response& res, Adaptor adaptorIn,
+ const crow::Request& reqIn, Adaptor adaptorIn,
std::function<void(Connection&, std::shared_ptr<bmcweb::AsyncResp>)>
open_handler,
std::function<void(Connection&, const std::string&, bool)>
message_handler,
std::function<void(Connection&, const std::string&)> close_handler,
std::function<void(Connection&)> error_handler) :
- Connection(reqIn, res),
+ Connection(reqIn),
ws(std::move(adaptorIn)), inString(), inBuffer(inString, 131088),
openHandler(std::move(open_handler)),
messageHandler(std::move(message_handler)),
@@ -80,12 +80,11 @@ template <typename Adaptor> class ConnectionImpl : public Connection
using bf = boost::beast::http::field;
- std::string_view protocol =
- req.getHeaderValue(bf::sec_websocket_protocol);
+ std::string_view protocol = req[bf::sec_websocket_protocol];
// Perform the websocket upgrade
ws.async_accept_ex(
- req.req,
+ req,
[protocol{std::string(protocol)}](
boost::beast::websocket::response_type& m) {
if (!protocol.empty())
OpenPOWER on IntegriCloud