diff options
author | Ed Tanous <edtanous@google.com> | 2021-12-07 01:14:43 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2021-12-15 23:20:18 +0300 |
commit | 88e1612b4141e9011a70fcb95c76238112051e62 (patch) | |
tree | f583eaced82ef5e26c07708dbdd3a37bd3694b33 /http/http_server.hpp | |
parent | 5dfb5b2d8826f568a0ad6f6430f01cd7a86ab07f (diff) | |
download | bmcweb-88e1612b4141e9011a70fcb95c76238112051e62.tar.xz |
Deduplicate doAccept code
doAccept does essentially the same code in two ways.
boost::beast::lowest_layer is used elsewhere to deduplicate this code.
Use it here as well.
Tested:
curl -vvvv --insecure -u root:0penBmc "https://192.168.7.2:443/redfish/v1"
succeeds.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Idfb0cd8f62ffbc09d6e248c677c24ea1abcb7a5b
Diffstat (limited to 'http/http_server.hpp')
-rw-r--r-- | http/http_server.hpp | 43 |
1 files changed, 15 insertions, 28 deletions
diff --git a/http/http_server.hpp b/http/http_server.hpp index 403778996d..bf4a091c6b 100644 --- a/http/http_server.hpp +++ b/http/http_server.hpp @@ -164,45 +164,32 @@ class Server void doAccept() { - std::optional<Adaptor> adaptorTemp; boost::asio::steady_timer timer(*ioService); + std::shared_ptr<Connection<Adaptor, Handler>> connection; if constexpr (std::is_same<Adaptor, boost::beast::ssl_stream< boost::asio::ip::tcp::socket>>::value) { - adaptorTemp = Adaptor(*ioService, *adaptorCtx); - auto p = std::make_shared<Connection<Adaptor, Handler>>( + connection = std::make_shared<Connection<Adaptor, Handler>>( handler, std::move(timer), getCachedDateStr, - std::move(adaptorTemp.value())); - - acceptor->async_accept(p->socket().next_layer(), - [this, p](boost::system::error_code ec) { - if (!ec) - { - boost::asio::post( - *this->ioService, - [p] { p->start(); }); - } - doAccept(); - }); + Adaptor(*ioService, *adaptorCtx)); } else { - adaptorTemp = Adaptor(*ioService); - auto p = std::make_shared<Connection<Adaptor, Handler>>( + connection = std::make_shared<Connection<Adaptor, Handler>>( handler, std::move(timer), getCachedDateStr, - std::move(adaptorTemp.value())); - - acceptor->async_accept( - p->socket(), [this, p](boost::system::error_code ec) { - if (!ec) - { - boost::asio::post(*this->ioService, - [p] { p->start(); }); - } - doAccept(); - }); + Adaptor(*ioService)); } + acceptor->async_accept( + boost::beast::get_lowest_layer(connection->socket()), + [this, connection](boost::system::error_code ec) { + if (!ec) + { + boost::asio::post(*this->ioService, + [connection] { connection->start(); }); + } + doAccept(); + }); } private: |