3

I implemented async_connect successfully using it as a free function and a lambda as connect_handler as follows:

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

However, now I'm forced to use the no_delay flag. Regarding this entry boost::asio with no_delay not possible? I have to call async_connect as member function of the socket. Trying as following

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

my compiler (VS2013) gives me an error Error 1 error C2338: ConnectHandler type requirements not met

Does someone has as idea, how to do it correctly?

Community
  • 1
  • 1
GregPhil
  • 475
  • 1
  • 8
  • 20

1 Answers1

2

The handler signature of the free function async_connect should be:

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

The handler signature of the member function basic_stream_socket::async_connect should be:

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

The reasoning is that you give multiple endpoints to the free function which then gives you back an iterator to tell you which one was connected while you only give one endpoint to the member function which doesn't have to tell you which one was connected since you only provided one.

So in order for you code to work you most likely just have to remove the iterator from the parameters of your lambda callback:

m_socket.async_connect(endpoint_iter->endpoint(), [this, self](boost::system::error_code ec){...}
Drax
  • 12,682
  • 7
  • 45
  • 85