C ++提高ASIO超时阻止连接 [英] c++ boost asio timeout for blocking connect

查看:202
本文介绍了C ++提高ASIO超时阻止连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C ++提高客户端做了阻塞连接,一旦收到响应处理消息。我面临的一个奇怪的问题。

I have a C++ boost client that does a blocking connect and processes the message once it receives a response. I am facing a strange issue.

tcp::resolver::query query(tcp::v6(), this->host, port,tcp::resolver::query::v4_mapped);
iterator = resolver.resolve(query);
socket = new tcp::socket(io_service);
socket->connect(*iterator);

我试图连接到一台机器,这不是由ping6到达(但启用IPV6)。不过,尽管试图解决线2的查询,我没有得到任何错误。作为这样的结果,它占用太多时间,同时试图提供错误之前的连接。我的问题: -

I tried to connect to a machine that was not reachable by ping6 (but was IPV6 enabled). Still, I didn't get any error while trying to resolve the query in line-2. As a result of this, it takes too much time while attempting a connection before giving an error. My questions:-

1)是否有可能从ASIO阻塞连接超时?我不能切换到运行的异步模式。

1) Is it possible to timeout on a blocking connect from asio? I cannot switch to async mode of operation.

2)如何来同时解决了无法访问的主机我没有得到一个错误?

2) How come I don't get an error while it resolves an unreachable host?

任何意见将是非常有益的多。

Any advice would be very much helpful

推荐答案

超时是同步的方法有错误的地方,有一个漫长的在ASIO票跟踪讨论

Timeouts are the wrong place for synchronous methods, there's a lengthy discussion in the asio ticket tracker.

我不能切换到异步模式
  操作。

I cannot switch to async mode of operation.

我觉得这不大可能给出的超时要求,发表您的code的休息,并解释为什么你不能使用异步操作。

I find this highly unlikely given the timeout requirement, post the rest of your code and explain why you cannot use asynchronous operations.

这篇关于C ++提高ASIO超时阻止连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆