116 lines
4.9 KiB
HTML
116 lines
4.9 KiB
HTML
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
<title>Resolve handler requirements</title>
|
|
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
|
|
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
|
|
<link rel="home" href="../../index.html" title="Asio">
|
|
<link rel="up" href="../reference.html" title="Reference">
|
|
<link rel="prev" href="Receiver.html" title="Receiver concepts">
|
|
<link rel="next" href="Scheduler.html" title="Scheduler concept">
|
|
</head>
|
|
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
|
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="asio C++ library" width="250" height="60" src="../../asio.png"></td></tr></table>
|
|
<hr>
|
|
<div class="spirit-nav">
|
|
<a accesskey="p" href="Receiver.html"><img src="../../prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../home.png" alt="Home"></a><a accesskey="n" href="Scheduler.html"><img src="../../next.png" alt="Next"></a>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="asio.reference.ResolveHandler"></a><a class="link" href="ResolveHandler.html" title="Resolve handler requirements">Resolve handler requirements</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
A resolve handler must meet the requirements for a <a class="link" href="Handler.html" title="Handlers">handler</a>.
|
|
A value <code class="computeroutput">h</code> of a resolve handler class should work correctly in
|
|
the expression <code class="computeroutput">h(ec, r)</code>, where <code class="computeroutput">ec</code> is an lvalue
|
|
of type <code class="computeroutput">const error_code</code> and <code class="computeroutput">r</code> is an lvalue of
|
|
type <code class="computeroutput">const ip::basic_resolver_results<InternetProtocol></code>.
|
|
<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<></code></a>
|
|
which is used to initiate the asynchronous operation.
|
|
</p>
|
|
<h5>
|
|
<a name="asio.reference.ResolveHandler.h0"></a>
|
|
<span><a name="asio.reference.ResolveHandler.examples"></a></span><a class="link" href="ResolveHandler.html#asio.reference.ResolveHandler.examples">Examples</a>
|
|
</h5>
|
|
<p>
|
|
A free function as a resolve handler:
|
|
</p>
|
|
<pre class="programlisting">void resolve_handler(
|
|
const asio::error_code& ec,
|
|
asio::ip::tcp::resolver::results_type results)
|
|
{
|
|
...
|
|
}
|
|
</pre>
|
|
<p>
|
|
A resolve handler function object:
|
|
</p>
|
|
<pre class="programlisting">struct resolve_handler
|
|
{
|
|
...
|
|
void operator()(
|
|
const asio::error_code& ec,
|
|
asio::ip::tcp::resolver::results_type results)
|
|
{
|
|
...
|
|
}
|
|
...
|
|
};
|
|
</pre>
|
|
<p>
|
|
A lambda as a resolve handler:
|
|
</p>
|
|
<pre class="programlisting">resolver.async_resolve(...,
|
|
[](const asio::error_code& ec,
|
|
asio::ip::tcp::resolver::results_type results)
|
|
{
|
|
...
|
|
});
|
|
</pre>
|
|
<p>
|
|
A non-static class member function adapted to a resolve handler using <code class="computeroutput">std::bind()</code>:
|
|
</p>
|
|
<pre class="programlisting">void my_class::resolve_handler(
|
|
const asio::error_code& ec,
|
|
asio::ip::tcp::resolver::results_type results)
|
|
{
|
|
...
|
|
}
|
|
...
|
|
resolver.async_resolve(...,
|
|
std::bind(&my_class::resolve_handler,
|
|
this, std::placeholders::_1,
|
|
std::placeholders::_2));
|
|
</pre>
|
|
<p>
|
|
A non-static class member function adapted to a resolve handler using <code class="computeroutput">boost::bind()</code>:
|
|
</p>
|
|
<pre class="programlisting">void my_class::resolve_handler(
|
|
const asio::error_code& ec,
|
|
asio::ip::tcp::resolver::results_type results)
|
|
{
|
|
...
|
|
}
|
|
...
|
|
resolver.async_resolve(...,
|
|
boost::bind(&my_class::resolve_handler,
|
|
this, asio::placeholders::error,
|
|
asio::placeholders::results));
|
|
</pre>
|
|
</div>
|
|
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
|
<td align="left"></td>
|
|
<td align="right"><div class="copyright-footer">Copyright © 2003-2020 Christopher M.
|
|
Kohlhoff<p>
|
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
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>)
|
|
</p>
|
|
</div></td>
|
|
</tr></table>
|
|
<hr>
|
|
<div class="spirit-nav">
|
|
<a accesskey="p" href="Receiver.html"><img src="../../prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../home.png" alt="Home"></a><a accesskey="n" href="Scheduler.html"><img src="../../next.png" alt="Next"></a>
|
|
</div>
|
|
</body>
|
|
</html>
|