1[/
2 / Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
3 /
4 / Distributed under the Boost Software License, Version 1.0. (See accompanying
5 / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 /]
7
8[section:RangeConnectHandler Range connect handler requirements]
9
10A range connect handler must meet the requirements for a [link
11boost_asio.reference.Handler handler]. A value `h` of a range connect handler class
12should work correctly in the expression `h(ec, ep)`, where `ec` is an lvalue of
13type `const error_code` and `ep` is an lvalue of the type `Protocol::endpoint`
14for the `Protocol` type in the corresponding `connect()` or async_connect()`
15function.
16
17[heading Examples]
18
19A free function as a range connect handler:
20
21  void connect_handler(
22      const boost::system::error_code& ec,
23      const boost::asio::ip::tcp::endpoint& endpoint)
24  {
25    ...
26  }
27
28A range connect handler function object:
29
30  struct connect_handler
31  {
32    ...
33    template <typename Range>
34    void operator()(
35        const boost::system::error_code& ec,
36        const boost::asio::ip::tcp::endpoint& endpoint)
37    {
38      ...
39    }
40    ...
41  };
42
43A lambda as a range connect handler:
44
45  boost::asio::async_connect(...,
46      [](const boost::system::error_code& ec,
47        const boost::asio::ip::tcp::endpoint& endpoint)
48      {
49        ...
50      });
51
52A non-static class member function adapted to a range connect handler using
53`std::bind()`:
54
55  void my_class::connect_handler(
56      const boost::system::error_code& ec,
57      const boost::asio::ip::tcp::endpoint& endpoint)
58  {
59    ...
60  }
61  ...
62  boost::asio::async_connect(...,
63      std::bind(&my_class::connect_handler,
64        this, std::placeholders::_1,
65        std::placeholders::_2));
66
67A non-static class member function adapted to a range connect handler using
68`boost::bind()`:
69
70  void my_class::connect_handler(
71      const boost::system::error_code& ec,
72      const boost::asio::ip::tcp::endpoint& endpoint)
73  {
74    ...
75  }
76  ...
77  boost::asio::async_connect(...,
78      boost::bind(&my_class::connect_handler,
79        this, boost::asio::placeholders::error,
80        boost::asio::placeholders::endpoint));
81
82[endsect]
83