• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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:IteratorConnectHandler Iterator connect handler requirements]
9
10An iterator connect handler must meet the requirements for a [link
11boost_asio.reference.Handler handler]. A value `h` of an iterator connect handler
12class should work correctly in the expression `h(ec, i)`, where `ec` is an
13lvalue of type `const error_code` and `i` is an lvalue of the type `Iterator`
14used in the corresponding `connect()` or async_connect()` function.
15
16[heading Examples]
17
18A free function as an iterator connect handler:
19
20  void connect_handler(
21      const boost::system::error_code& ec,
22      boost::asio::ip::tcp::resolver::iterator iterator)
23  {
24    ...
25  }
26
27An iterator connect handler function object:
28
29  struct connect_handler
30  {
31    ...
32    template <typename Iterator>
33    void operator()(
34        const boost::system::error_code& ec,
35        Iterator iterator)
36    {
37      ...
38    }
39    ...
40  };
41
42A lambda as an iterator connect handler:
43
44  boost::asio::async_connect(...,
45      [](const boost::system::error_code& ec,
46        boost::asio::ip::tcp::resolver::iterator iterator)
47      {
48        ...
49      });
50
51A non-static class member function adapted to an iterator connect handler using
52`std::bind()`:
53
54  void my_class::connect_handler(
55      const boost::system::error_code& ec,
56      boost::asio::ip::tcp::resolver::iterator iterator)
57  {
58    ...
59  }
60  ...
61  boost::asio::async_connect(...,
62      std::bind(&my_class::connect_handler,
63        this, std::placeholders::_1,
64        std::placeholders::_2));
65
66A non-static class member function adapted to an iterator connect handler using
67`boost::bind()`:
68
69  void my_class::connect_handler(
70      const boost::system::error_code& ec,
71      boost::asio::ip::tcp::resolver::iterator iterator)
72  {
73    ...
74  }
75  ...
76  boost::asio::async_connect(...,
77      boost::bind(&my_class::connect_handler,
78        this, boost::asio::placeholders::error,
79        boost::asio::placeholders::iterator));
80
81[endsect]
82