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