std :: runtime_error:resolve:在boost :: asio中找不到主机(权威)

时间:2017-11-16 09:26:24

标签: c++ macos boost boost-asio resolve

以下代码:

function myFontStyle() {
  $('#font').on("change", function() {
    var fontChange = this.value
    console.log(this.value);

    $('h1').attr('class', fontChange);
  });
}
myFontStyle(); 
使用Xcode 9.1在OS X High Sierra上运行时,

会导致以下错误:

using boost::asio::ip::tcp;

std::string ipAddress;

boost::asio::io_service io_service;
tcp::resolver resolver(io_service);
tcp::resolver::query query(boost::asio::ip::host_name(), "");

tcp::resolver::iterator iter = resolver.resolve(query);

std::runtime_error: resolve: Host not found (authoritative) 的值为:

resolver

(boost::asio::ip::tcp::resolver) resolver = { boost::asio::basic_io_object<boost::asio::ip::resolver_service<boost::asio::ip::tcp>, false> = { service = 0x00000001023159a0 implementation = nullptr { __ptr_ = 0x0000000000000000 __cntrl_ = 0x00000001023156c0 } } } 的值为:

query

(boost::asio::ip::basic_resolver<boost::asio::ip::tcp, boost::asio::ip::resolver_service<boost::asio::ip::tcp> >::query) query = { hints_ = { ai_flags = 1024 ai_family = 0 ai_socktype = 1 ai_protocol = 6 ai_addrlen = 0 ai_canonname = 0x0000000000000000 ai_addr = 0x0000000000000000 ai_next = 0x0000000000000000 } host_name_ = "iMac.local" service_name_ = "" } 函数如下所示:

resolve

所以我可以看到调用iterator resolve(const query& q) { boost::system::error_code ec; iterator i = this->service.resolve(this->implementation, q, ec); boost::asio::detail::throw_error(ec, "resolve"); return i; } resolveresolver.implementation是导致问题的原因。但是,我不知道为什么它是nullptr

在运行OS X Yosemite或El Capitan的不同计算机上,这不是问题。

1 个答案:

答案 0 :(得分:1)

发布答案以防其他人遇到相同问题并最终结束。

最后想出来了,部分归功于 一些程序员家伙 询问ping主机然后根据ping失败的事实进行搜索。

此帖子https://discussions.apple.com/thread/7707202?start=0&tstart=0表示由于某种原因。除非任何共享服务处于活动状态,否则.local主机名将保持关闭状态。

打开它们可以解决问题。