OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
resolve.hpp
1#pragma once
2
4
5#include <boost/asio/io_context.hpp>
6#include <boost/asio/ip/basic_resolver.hpp>
7#include <boost/asio/ip/tcp.hpp>
8
9namespace ossia
10{
11inline bool resolve_sync_v4(std::string& host, std::string_view port)
12{
13 try
14 {
15 boost::asio::io_context io_service;
16
17 boost::asio::ip::tcp::resolver resolver(io_service);
18 auto results = resolver.resolve(
19 boost::asio::ip::tcp::v4(), host, port,
20 boost::asio::ip::resolver_base::numeric_service);
21
22 for(auto& result : results)
23 {
24 if(result.endpoint().address().is_loopback())
25 {
26 host = "127.0.0.1";
27 return true;
28 }
29 else if(result.endpoint().address().is_v4())
30 {
31 host = result.endpoint().address().to_string();
32 }
33 }
34 return true;
35 }
36 catch(const std::exception& e)
37 {
38 ossia::logger().error("Could not resolve host: {} => {}", host, e.what());
39 }
40 return false;
41}
42}
Definition git_info.h:7
spdlog::logger & logger() noexcept
Where the errors will be logged. Default is stderr.
Definition context.cpp:118