diff options
author | Ed Tanous <edtanous@google.com> | 2021-12-03 22:24:53 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2021-12-15 23:20:18 +0300 |
commit | 5dfb5b2d8826f568a0ad6f6430f01cd7a86ab07f (patch) | |
tree | e91885881f1db3535378a7e82323792407609b14 /http/http_server.hpp | |
parent | 5ae4b692fcee7d27c1e1a5a7c6efbd375a76dacc (diff) | |
download | bmcweb-5dfb5b2d8826f568a0ad6f6430f01cd7a86ab07f.tar.xz |
Make timer system use boost
The original crow timeout system had a timer queue setup for handling
many thousands of connections at a time efficiently. The most common
use cases for the bmc involve a handful of connections, so this code
doesn't help us much.
These days, boost asio also implements a very similar timer queue
https://www.boost.org/doc/libs/1_72_0/boost/asio/detail/timer_queue.hpp
internally, so the only thing we're loosing here is the "fuzzy"
coalescing of timeout actions, for which it's tough to say if anyone
will even notice.
This commit implements a timer system that's self contained within each
connection, using steady_timer. This is much more "normal" and how most
of the beast examples implement timers.
Tested:
Minimal touch testing to ensure that things work, but more testing is
required, probably using sloworis to ensure that our timeouts are no
longer issues.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I19156411ce46adff6c88ad97ee8f6af8c858fe3c
Diffstat (limited to 'http/http_server.hpp')
-rw-r--r-- | http/http_server.hpp | 29 |
1 files changed, 6 insertions, 23 deletions
diff --git a/http/http_server.hpp b/http/http_server.hpp index 20b4e5084a..403778996d 100644 --- a/http/http_server.hpp +++ b/http/http_server.hpp @@ -2,7 +2,6 @@ #include "http_connection.hpp" #include "logging.hpp" -#include "timer_queue.hpp" #include <boost/asio/ip/address.hpp> #include <boost/asio/ip/tcp.hpp> @@ -36,8 +35,8 @@ class Server std::make_shared<boost::asio::io_context>()) : ioService(std::move(io)), acceptor(std::move(acceptorIn)), - signals(*ioService, SIGINT, SIGTERM, SIGHUP), timer(*ioService), - handler(handlerIn), adaptorCtx(std::move(adaptorCtx)) + signals(*ioService, SIGINT, SIGTERM, SIGHUP), handler(handlerIn), + adaptorCtx(std::move(adaptorCtx)) {} Server(Handler* handlerIn, const std::string& bindaddr, uint16_t port, @@ -91,19 +90,6 @@ class Server return this->dateStr; }; - timer.expires_after(std::chrono::seconds(1)); - - timerHandler = [this](const boost::system::error_code& ec) { - if (ec) - { - return; - } - timerQueue.process(); - timer.expires_after(std::chrono::seconds(1)); - timer.async_wait(timerHandler); - }; - timer.async_wait(timerHandler); - BMCWEB_LOG_INFO << "bmcweb server is running, local endpoint " << acceptor->local_endpoint(); startAsyncWaitForSignal(); @@ -179,13 +165,14 @@ class Server void doAccept() { std::optional<Adaptor> adaptorTemp; + boost::asio::steady_timer timer(*ioService); 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>>( - handler, getCachedDateStr, timerQueue, + handler, std::move(timer), getCachedDateStr, std::move(adaptorTemp.value())); acceptor->async_accept(p->socket().next_layer(), @@ -203,7 +190,7 @@ class Server { adaptorTemp = Adaptor(*ioService); auto p = std::make_shared<Connection<Adaptor, Handler>>( - handler, getCachedDateStr, timerQueue, + handler, std::move(timer), getCachedDateStr, std::move(adaptorTemp.value())); acceptor->async_accept( @@ -220,21 +207,17 @@ class Server private: std::shared_ptr<boost::asio::io_context> ioService; - detail::TimerQueue timerQueue; std::function<std::string()> getCachedDateStr; std::unique_ptr<boost::asio::ip::tcp::acceptor> acceptor; boost::asio::signal_set signals; - boost::asio::steady_timer timer; std::string dateStr; Handler* handler; - std::function<void(const boost::system::error_code& ec)> timerHandler; - #ifdef BMCWEB_ENABLE_SSL bool useSsl{false}; #endif std::shared_ptr<boost::asio::ssl::context> adaptorCtx; -}; // namespace crow +}; } // namespace crow |