diff options
Diffstat (limited to 'http')
-rw-r--r-- | http/app.hpp | 5 | ||||
-rw-r--r-- | http/http_client.hpp | 32 |
2 files changed, 25 insertions, 12 deletions
diff --git a/http/app.hpp b/http/app.hpp index a3a6e16255..d3cf48c1b1 100644 --- a/http/app.hpp +++ b/http/app.hpp @@ -183,6 +183,11 @@ class App } #endif + boost::asio::io_context& ioContext() + { + return *io; + } + private: std::shared_ptr<boost::asio::io_context> io; #ifdef BMCWEB_ENABLE_SSL diff --git a/http/http_client.hpp b/http/http_client.hpp index 2b498b7fb8..7a98b54497 100644 --- a/http/http_client.hpp +++ b/http/http_client.hpp @@ -146,7 +146,14 @@ class ConnectionInfo : public std::enable_shared_from_this<ConnectionInfo> // Ascync callables std::function<void(bool, uint32_t, Response&)> callback; - crow::async_resolve::Resolver resolver; + +#ifdef BMCWEB_DBUS_DNS_RESOLVER + using Resolver = crow::async_resolve::Resolver; +#else + using Resolver = boost::asio::ip::tcp::resolver; +#endif + Resolver resolver; + boost::asio::ip::tcp::socket conn; std::optional<boost::beast::ssl_stream<boost::asio::ip::tcp::socket&>> sslConn; @@ -162,15 +169,14 @@ class ConnectionInfo : public std::enable_shared_from_this<ConnectionInfo> << std::to_string(port) << ", id: " << std::to_string(connId); - resolver.asyncResolve(host, port, - std::bind_front(&ConnectionInfo::afterResolve, - this, shared_from_this())); + resolver.async_resolve(host, std::to_string(port), + std::bind_front(&ConnectionInfo::afterResolve, + this, shared_from_this())); } - void afterResolve( - const std::shared_ptr<ConnectionInfo>& /*self*/, - const boost::beast::error_code& ec, - const std::vector<boost::asio::ip::tcp::endpoint>& endpointList) + void afterResolve(const std::shared_ptr<ConnectionInfo>& /*self*/, + const boost::system::error_code& ec, + const Resolver::results_type& endpointList) { if (ec || (endpointList.empty())) { @@ -591,7 +597,7 @@ class ConnectionInfo : public std::enable_shared_from_this<ConnectionInfo> unsigned int connIdIn) : subId(idIn), connPolicy(connPolicyIn), host(destIPIn), port(destPortIn), - connId(connIdIn), conn(iocIn), timer(iocIn) + connId(connIdIn), resolver(iocIn), conn(iocIn), timer(iocIn) { if (useSSL) { @@ -833,8 +839,7 @@ class HttpClient private: std::unordered_map<std::string, std::shared_ptr<ConnectionPool>> connectionPools; - boost::asio::io_context& ioc = - crow::connections::systemBus->get_io_context(); + boost::asio::io_context& ioc; std::shared_ptr<ConnectionPolicy> connPolicy; // Used as a dummy callback by sendData() in order to call @@ -847,9 +852,12 @@ class HttpClient public: HttpClient() = delete; - explicit HttpClient(const std::shared_ptr<ConnectionPolicy>& connPolicyIn) : + explicit HttpClient(boost::asio::io_context& iocIn, + const std::shared_ptr<ConnectionPolicy>& connPolicyIn) : + ioc(iocIn), connPolicy(connPolicyIn) {} + HttpClient(const HttpClient&) = delete; HttpClient& operator=(const HttpClient&) = delete; HttpClient(HttpClient&&) = delete; |