Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Connect token requirements

A connect token is a completion token for completion signature void(error_code).

Examples

A free function as a connect token:

void connect_handler(
    const boost::system::error_code& ec)
{
  ...
}

A connect token function object:

struct connect_handler
{
  ...
  void operator()(
      const boost::system::error_code& ec)
  {
    ...
  }
  ...
};

A lambda as a connect token:

socket.async_connect(...,
    [](const boost::system::error_code& ec)
    {
      ...
    });

A non-static class member function adapted to a connect token using std::bind():

void my_class::connect_handler(
    const boost::system::error_code& ec)
{
  ...
}
...
socket.async_connect(...,
    std::bind(&my_class::connect_handler,
      this, std::placeholders::_1));

A non-static class member function adapted to a connect token using boost::bind():

void my_class::connect_handler(
    const boost::system::error_code& ec)
{
  ...
}
...
socket.async_connect(...,
    boost::bind(&my_class::connect_handler,
      this, boost::asio::placeholders::error));

Using use_future as a connect token:

std::future<void> f = socket.async_connect(..., boost::asio::use_future);
...
try
{
  f.get();
}
catch (const system_error& e)
{
  ...
}

Using use_awaitable as a connect token:

boost::asio::awaitable<void> my_coroutine()
{
  try
  {
    ...
    co_await socket.async_connect(..., boost::asio::use_awaitable);
    ...
  }
  catch (const system_error& e)
  {
    ...
  }
}

PrevUpHomeNext