Allow async resolver to be optional
This commit adds a meson option to allow selecting which dns resolver
bmcweb uses. There are use cases, like Open Compute Project Inband
Management Agent, that would require not using dbus, which would require
us to fall back to the asio resolver. This commit makes the existing
asio resolver constructor, and async_resolve methods match the
equivalents in asio (which we intended to do anyway), then adds a macro
and configure option for being able to select which resolver backend to
rely on.
Tested: Code can now compile without sdbusplus.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I3220214367179f131a60082bdfaf7e725d35c125
diff --git a/http/http_client.hpp b/http/http_client.hpp
index 2b498b7..7a98b54 100644
--- a/http/http_client.hpp
+++ b/http/http_client.hpp
@@ -146,7 +146,14 @@
// 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 @@
<< 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 @@
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 @@
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 @@
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;