2017-02-09 25 views
1

async_connect成功地使用它作为一个免费的功能和lambda作为connect_handler执行如下成员函数:如何调用提振async_connect如使用兰巴作为连接处理器

auto self(shared_from_this()); 
boost::asio::async_connect(m_socket, endpoint_iter, [this, self](boost::system::error_code ec, tcp::resolver::iterator){...} 

不过,现在我被迫使用no_delay标志。关于此条目boost::asio with no_delay not possible?我必须调用async_connect作为套接字的成员函数。尝试如下

m_socket.async_connect(endpoint_iter->endpoint(), [this, self](boost::system::error_code ec, tcp::resolver::iterator){...} 

我的编译器(VS2013)给我一个错误Error 1 error C2338: ConnectHandler type requirements not met

是否有人为的想法,怎么做是正确的?

回答

1

自由功能async_connect的处理程序签名应该是:

void handler(const boost::system::error_code& error, Iterator iterator); 

成员函数basic_stream_socket::async_connect的处理程序签名应该是:

void handler(const boost::system::error_code& error); 

的原因是你给多个端点到自由函数然后给你一个迭代器,告诉你哪一个被连接,而你只给一个端点给成员函数,而不必告诉你哪一个被连接,因为你只提供一个。

因此,为了使你的代码工作,你很可能只需要您的拉姆达回调的参数删除迭代:

m_socket.async_connect(endpoint_iter->endpoint(), [this, self](boost::system::error_code ec){...} 
+1

非常感谢您!我只是验证它,它的工作! – GregPhil

相关问题