]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | [/ |
2 | / Copyright (c) 2003-2016 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 | ||
10 | A resolve handler must meet the requirements for a [link | |
11 | boost_asio.reference.Handler handler]. A value `h` of a resolve handler | |
12 | class should work correctly in the expression `h(ec, i)`, where `ec` is an | |
13 | lvalue of type `const error_code` and `i` is an lvalue of type `const | |
14 | ip::basic_resolver_iterator<InternetProtocol>`. `InternetProtocol` is the | |
15 | template parameter of the [link boost_asio.reference.ip__resolver_service | |
16 | `resolver_service`] which is used to initiate the asynchronous operation. | |
17 | ||
18 | [heading Examples] | |
19 | ||
20 | A free function as a resolve handler: | |
21 | ||
22 | void resolve_handler( | |
23 | const boost::system::error_code& ec, | |
24 | boost::asio::ip::tcp::resolver::iterator iterator) | |
25 | { | |
26 | ... | |
27 | } | |
28 | ||
29 | A 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::iterator iterator) | |
37 | { | |
38 | ... | |
39 | } | |
40 | ... | |
41 | }; | |
42 | ||
43 | A non-static class member function adapted to a resolve handler using `bind()`: | |
44 | ||
45 | void my_class::resolve_handler( | |
46 | const boost::system::error_code& ec, | |
47 | boost::asio::ip::tcp::resolver::iterator iterator) | |
48 | { | |
49 | ... | |
50 | } | |
51 | ... | |
52 | resolver.async_resolve(..., | |
53 | boost::bind(&my_class::resolve_handler, | |
54 | this, boost::asio::placeholders::error, | |
55 | boost::asio::placeholders::iterator)); | |
56 | ||
57 | [endsect] |