Commit cf36cd3a authored by Raphael Defosseux's avatar Raphael Defosseux

feat(fqdn): giving some time for FQDN resolution

Signed-off-by: default avatarRaphael Defosseux <raphael.defosseux@openairinterface.org>
parent 5d3fd80b
...@@ -23,12 +23,19 @@ ...@@ -23,12 +23,19 @@
#include "logger.hpp" #include "logger.hpp"
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include <iostream> #include <iostream>
#include <unistd.h>
#define MAX_NB_RESOLVE_TRIES 4
#define TIME_BETWEEN_TRIES 2
bool fqdn::resolve( bool fqdn::resolve(
const std::string& host_name, std::string& address, uint32_t& port, const std::string& host_name, std::string& address, uint32_t& port,
uint8_t& addr_type, const std::string& protocol) { uint8_t& addr_type, const std::string& protocol) {
int tries = 0;
while (tries < MAX_NB_RESOLVE_TRIES) {
try { try {
boost::asio::io_context io_context = {}; boost::asio::io_context io_context = {};
Logger::smf_app().debug("Resolving DNS Try #%u", tries);
boost::asio::ip::tcp::resolver resolver{io_context}; boost::asio::ip::tcp::resolver resolver{io_context};
boost::asio::ip::tcp::resolver::results_type endpoints = boost::asio::ip::tcp::resolver::results_type endpoints =
...@@ -50,10 +57,16 @@ bool fqdn::resolve( ...@@ -50,10 +57,16 @@ bool fqdn::resolve(
return true; return true;
} }
} catch (std::exception& e) { } catch (std::exception& e) {
tries++;
if (tries == MAX_NB_RESOLVE_TRIES) {
throw std::runtime_error( throw std::runtime_error(
"Cannot resolve a DNS name " + std::string(e.what())); "Cannot resolve a DNS name " + std::string(e.what()) + " after " +
std::to_string(tries) + " tries");
return false; return false;
} }
sleep(TIME_BETWEEN_TRIES);
}
}
return false; return false;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment