]>
Commit | Line | Data |
---|---|---|
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:ComposedConnectHandler Composed connect handler requirements] | |
9 | ||
10 | A composed connect handler must meet the requirements for a [link | |
11 | boost_asio.reference.Handler handler]. A value `h` of a composed connect 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 the type `Iterator` | |
14 | used in the corresponding `connect()` or async_connect()` function. | |
15 | ||
16 | [heading Examples] | |
17 | ||
18 | A free function as a composed 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 | ||
27 | A composed 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 | ||
42 | A non-static class member function adapted to a composed connect handler using `bind()`: | |
43 | ||
44 | void my_class::connect_handler( | |
45 | const boost::system::error_code& ec, | |
46 | boost::asio::ip::tcp::resolver::iterator iterator) | |
47 | { | |
48 | ... | |
49 | } | |
50 | ... | |
51 | boost::asio::async_connect(..., | |
52 | boost::bind(&my_class::connect_handler, | |
53 | this, boost::asio::placeholders::error, | |
54 | boost::asio::placeholders::iterator)); | |
55 | ||
56 | [endsect] |