summaryrefslogtreecommitdiff
path: root/http/http_server.h
diff options
context:
space:
mode:
authorJan Sowinski <jan.sowinski@intel.com>2019-12-03 12:37:06 +0300
committerJan Sowinski <jan.sowinski@intel.com>2019-12-19 16:01:38 +0300
commitc00500bcb9c5145f5cacb78bbe3dd694fb85ba0a (patch)
tree0aa8d2616be800b68fe7091e3e67b50f7b3326c9 /http/http_server.h
parentcac94c55c59a397524a04786f4d699e2bd7f21bf (diff)
downloadbmcweb-c00500bcb9c5145f5cacb78bbe3dd694fb85ba0a.tar.xz
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/http_server.h')
-rw-r--r--http/http_server.h25
1 files changed, 9 insertions, 16 deletions
diff --git a/http/http_server.h b/http/http_server.h
index df42214c88..6e63cbd418 100644
--- a/http/http_server.h
+++ b/http/http_server.h
@@ -44,7 +44,8 @@ class Server
ioService(std::move(io)),
acceptor(std::move(acceptor)),
signals(*ioService, SIGINT, SIGTERM, SIGHUP), tickTimer(*ioService),
- handler(handler), middlewares(middlewares), adaptorCtx(adaptor_ctx)
+ timer(*ioService), handler(handler), middlewares(middlewares),
+ adaptorCtx(adaptor_ctx)
{
}
@@ -123,11 +124,9 @@ class Server
return this->dateStr;
};
- boost::asio::steady_timer timer(*ioService);
timer.expires_after(std::chrono::seconds(1));
- std::function<void(const boost::system::error_code& ec)> timerHandler;
- timerHandler = [&](const boost::system::error_code& ec) {
+ timerHandler = [this](const boost::system::error_code& ec) {
if (ec)
{
return;
@@ -231,8 +230,8 @@ class Server
boost::asio::ip::tcp::socket>>::value)
{
adaptorTemp = Adaptor(*ioService, *adaptorCtx);
- Connection<Adaptor, Handler, Middlewares...>* p =
- new Connection<Adaptor, Handler, Middlewares...>(
+ auto p =
+ std::make_shared<Connection<Adaptor, Handler, Middlewares...>>(
*ioService, handler, serverName, middlewares,
getCachedDateStr, timerQueue,
std::move(adaptorTemp.value()));
@@ -245,18 +244,14 @@ class Server
*this->ioService,
[p] { p->start(); });
}
- else
- {
- delete p;
- }
doAccept();
});
}
else
{
adaptorTemp = Adaptor(*ioService);
- Connection<Adaptor, Handler, Middlewares...>* p =
- new Connection<Adaptor, Handler, Middlewares...>(
+ auto p =
+ std::make_shared<Connection<Adaptor, Handler, Middlewares...>>(
*ioService, handler, serverName, middlewares,
getCachedDateStr, timerQueue,
std::move(adaptorTemp.value()));
@@ -268,10 +263,6 @@ class Server
boost::asio::post(*this->ioService,
[p] { p->start(); });
}
- else
- {
- delete p;
- }
doAccept();
});
}
@@ -284,6 +275,7 @@ class Server
std::unique_ptr<tcp::acceptor> acceptor;
boost::asio::signal_set signals;
boost::asio::steady_timer tickTimer;
+ boost::asio::steady_timer timer;
std::string dateStr;
@@ -292,6 +284,7 @@ class Server
std::chrono::milliseconds tickInterval{};
std::function<void()> tickFunction;
+ std::function<void(const boost::system::error_code& ec)> timerHandler;
std::tuple<Middlewares...>* middlewares;