I want to reliaze how to use boost::aio::async_connect with lambda. Boost version 1.68
It's really strange that I could use std::bind but not lambda. If I use std::bind, it work. But when I use lambda, it buillt failed, and said "IteratorConnectHandler type requirements not met.
std::bind version (worked)
void SslClient::connect(boost::asio::ip::tcp::resolver::results_type results) {
auto sp = shared_from_this();
boost::asio::async_connect(ws->next_layer().next_layer(),
results.begin(),
results.end(),
std::bind(
on_connect,
std::placeholders::_1)
);
}
lambda version (not worked)
void SslClient::connect(boost::asio::ip::tcp::resolver::results_type results) {
auto sp = shared_from_this();
boost::asio::async_connect(ws->next_layer().next_layer(),
results.begin(),
results.end(),
[&, sp](boost::system::error_code ec) {
if (ec) {
return;
}
ws->next_layer().async_handshake(boost::asio::ssl::stream_base::client,
[&, sp](boost::system::error_code ec1) {
handShake(ec);
});
}
);
}
So how to use lambda here?
Aucun commentaire:
Enregistrer un commentaire