• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Resolve handler requirements</title>
5<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../../boost_asio.html" title="Boost.Asio">
8<link rel="up" href="../reference.html" title="Reference">
9<link rel="prev" href="Receiver.html" title="Receiver concepts">
10<link rel="next" href="Scheduler.html" title="Scheduler concept">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%"><tr>
14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td>
15<td align="center"><a href="../../../../index.html">Home</a></td>
16<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19<td align="center"><a href="../../../../more/index.htm">More</a></td>
20</tr></table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="Receiver.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../boost_asio.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="Scheduler.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h3 class="title">
27<a name="boost_asio.reference.ResolveHandler"></a><a class="link" href="ResolveHandler.html" title="Resolve handler requirements">Resolve handler
28      requirements</a>
29</h3></div></div></div>
30<p>
31        A resolve handler must meet the requirements for a <a class="link" href="Handler.html" title="Handlers">handler</a>.
32        A value <code class="computeroutput">h</code> of a resolve handler class should work correctly in
33        the expression <code class="computeroutput">h(ec, r)</code>, where <code class="computeroutput">ec</code> is an lvalue
34        of type <code class="computeroutput">const error_code</code> and <code class="computeroutput">r</code> is an lvalue of
35        type <code class="computeroutput">const ip::basic_resolver_results&lt;InternetProtocol&gt;</code>.
36        <code class="computeroutput">InternetProtocol</code> is the template parameter of the <a class="link" href="ip__basic_resolver.html" title="ip::basic_resolver"><code class="computeroutput">ip::basic_resolver&lt;&gt;</code></a>
37        which is used to initiate the asynchronous operation.
38      </p>
39<h5>
40<a name="boost_asio.reference.ResolveHandler.h0"></a>
41        <span class="phrase"><a name="boost_asio.reference.ResolveHandler.examples"></a></span><a class="link" href="ResolveHandler.html#boost_asio.reference.ResolveHandler.examples">Examples</a>
42      </h5>
43<p>
44        A free function as a resolve handler:
45      </p>
46<pre class="programlisting">void resolve_handler(
47    const boost::system::error_code&amp; ec,
48    boost::asio::ip::tcp::resolver::results_type results)
49{
50  ...
51}
52</pre>
53<p>
54        A resolve handler function object:
55      </p>
56<pre class="programlisting">struct resolve_handler
57{
58  ...
59  void operator()(
60      const boost::system::error_code&amp; ec,
61      boost::asio::ip::tcp::resolver::results_type results)
62  {
63    ...
64  }
65  ...
66};
67</pre>
68<p>
69        A lambda as a resolve handler:
70      </p>
71<pre class="programlisting">resolver.async_resolve(...,
72    [](const boost::system::error_code&amp; ec,
73      boost::asio::ip::tcp::resolver::results_type results)
74    {
75      ...
76    });
77</pre>
78<p>
79        A non-static class member function adapted to a resolve handler using <code class="computeroutput">std::bind()</code>:
80      </p>
81<pre class="programlisting">void my_class::resolve_handler(
82    const boost::system::error_code&amp; ec,
83    boost::asio::ip::tcp::resolver::results_type results)
84{
85  ...
86}
87...
88resolver.async_resolve(...,
89    std::bind(&amp;my_class::resolve_handler,
90      this, std::placeholders::_1,
91      std::placeholders::_2));
92</pre>
93<p>
94        A non-static class member function adapted to a resolve handler using <code class="computeroutput">boost::bind()</code>:
95      </p>
96<pre class="programlisting">void my_class::resolve_handler(
97    const boost::system::error_code&amp; ec,
98    boost::asio::ip::tcp::resolver::results_type results)
99{
100  ...
101}
102...
103resolver.async_resolve(...,
104    boost::bind(&amp;my_class::resolve_handler,
105      this, boost::asio::placeholders::error,
106      boost::asio::placeholders::results));
107</pre>
108</div>
109<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
110<td align="left"></td>
111<td align="right"><div class="copyright-footer">Copyright © 2003-2020 Christopher M.
112      Kohlhoff<p>
113        Distributed under the Boost Software License, Version 1.0. (See accompanying
114        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
115      </p>
116</div></td>
117</tr></table>
118<hr>
119<div class="spirit-nav">
120<a accesskey="p" href="Receiver.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../boost_asio.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="Scheduler.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
121</div>
122</body>
123</html>
124