Insane_DNS/libraries/asio-1.28.1/doc/asio/reference/ResolveToken.html

146 lines
14 KiB
HTML
Raw Permalink Normal View History

2023-10-24 21:59:30 -04:00
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Resolve token 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="ResolveHandler.html" title="Resolve handler requirements">
<link rel="next" href="Scheduler.html" title="Scheduler concept">
<meta name="viewport" content="width=device-width, initial-scale=1">
</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="ResolveHandler.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.ResolveToken"></a><a class="link" href="ResolveToken.html" title="Resolve token requirements">Resolve token requirements</a>
</h3></div></div></div>
<p>
A resolve token is a <a class="link" href="../overview/model/completion_tokens.html" title="Completion Tokens">completion
token</a> for completion signature <code class="computeroutput"><span class="keyword">void</span><span class="special">(</span><span class="identifier">error_code</span><span class="special">,</span> <span class="identifier">ip</span><span class="special">::</span><span class="identifier">basic_resolver_results</span><span class="special">&lt;</span><span class="identifier">InternetProtocol</span><span class="special">&gt;)</span></code>,
for a specified <code class="computeroutput"><span class="identifier">InternetProtocol</span></code>.
</p>
<h5>
<a name="asio.reference.ResolveToken.h0"></a>
<span><a name="asio.reference.ResolveToken.examples"></a></span><a class="link" href="ResolveToken.html#asio.reference.ResolveToken.examples">Examples</a>
</h5>
<p>
A free function as a resolve token:
</p>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">resolve_handler</span><span class="special">(</span>
<span class="keyword">const</span> <span class="identifier">asio</span><span class="special">::</span><span class="identifier">error_code</span><span class="special">&amp;</span> <span class="identifier">ec</span><span class="special">,</span>
<span class="identifier">asio</span><span class="special">::</span><span class="identifier">ip</span><span class="special">::</span><span class="identifier">tcp</span><span class="special">::</span><span class="identifier">resolver</span><span class="special">::</span><span class="identifier">results_type</span> <span class="identifier">results</span><span class="special">)</span>
<span class="special">{</span>
<span class="special">...</span>
<span class="special">}</span>
</pre>
<p>
A resolve token function object:
</p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">resolve_handler</span>
<span class="special">{</span>
<span class="special">...</span>
<span class="keyword">void</span> <span class="keyword">operator</span><span class="special">()(</span>
<span class="keyword">const</span> <span class="identifier">asio</span><span class="special">::</span><span class="identifier">error_code</span><span class="special">&amp;</span> <span class="identifier">ec</span><span class="special">,</span>
<span class="identifier">asio</span><span class="special">::</span><span class="identifier">ip</span><span class="special">::</span><span class="identifier">tcp</span><span class="special">::</span><span class="identifier">resolver</span><span class="special">::</span><span class="identifier">results_type</span> <span class="identifier">results</span><span class="special">)</span>
<span class="special">{</span>
<span class="special">...</span>
<span class="special">}</span>
<span class="special">...</span>
<span class="special">};</span>
</pre>
<p>
A lambda as a resolve token:
</p>
<pre class="programlisting"><span class="identifier">resolver</span><span class="special">.</span><span class="identifier">async_resolve</span><span class="special">(...,</span>
<span class="special">[](</span><span class="keyword">const</span> <span class="identifier">asio</span><span class="special">::</span><span class="identifier">error_code</span><span class="special">&amp;</span> <span class="identifier">ec</span><span class="special">,</span>
<span class="identifier">asio</span><span class="special">::</span><span class="identifier">ip</span><span class="special">::</span><span class="identifier">tcp</span><span class="special">::</span><span class="identifier">resolver</span><span class="special">::</span><span class="identifier">results_type</span> <span class="identifier">results</span><span class="special">)</span>
<span class="special">{</span>
<span class="special">...</span>
<span class="special">});</span>
</pre>
<p>
A non-static class member function adapted to a resolve token using <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">bind</span><span class="special">()</span></code>:
</p>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">my_class</span><span class="special">::</span><span class="identifier">resolve_handler</span><span class="special">(</span>
<span class="keyword">const</span> <span class="identifier">asio</span><span class="special">::</span><span class="identifier">error_code</span><span class="special">&amp;</span> <span class="identifier">ec</span><span class="special">,</span>
<span class="identifier">asio</span><span class="special">::</span><span class="identifier">ip</span><span class="special">::</span><span class="identifier">tcp</span><span class="special">::</span><span class="identifier">resolver</span><span class="special">::</span><span class="identifier">results_type</span> <span class="identifier">results</span><span class="special">)</span>
<span class="special">{</span>
<span class="special">...</span>
<span class="special">}</span>
<span class="special">...</span>
<span class="identifier">resolver</span><span class="special">.</span><span class="identifier">async_resolve</span><span class="special">(...,</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(&amp;</span><span class="identifier">my_class</span><span class="special">::</span><span class="identifier">resolve_handler</span><span class="special">,</span>
<span class="keyword">this</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">placeholders</span><span class="special">::</span><span class="identifier">_1</span><span class="special">,</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">placeholders</span><span class="special">::</span><span class="identifier">_2</span><span class="special">));</span>
</pre>
<p>
A non-static class member function adapted to a resolve token using <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">()</span></code>:
</p>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">my_class</span><span class="special">::</span><span class="identifier">resolve_handler</span><span class="special">(</span>
<span class="keyword">const</span> <span class="identifier">asio</span><span class="special">::</span><span class="identifier">error_code</span><span class="special">&amp;</span> <span class="identifier">ec</span><span class="special">,</span>
<span class="identifier">asio</span><span class="special">::</span><span class="identifier">ip</span><span class="special">::</span><span class="identifier">tcp</span><span class="special">::</span><span class="identifier">resolver</span><span class="special">::</span><span class="identifier">results_type</span> <span class="identifier">results</span><span class="special">)</span>
<span class="special">{</span>
<span class="special">...</span>
<span class="special">}</span>
<span class="special">...</span>
<span class="identifier">resolver</span><span class="special">.</span><span class="identifier">async_resolve</span><span class="special">(...,</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(&amp;</span><span class="identifier">my_class</span><span class="special">::</span><span class="identifier">resolve_handler</span><span class="special">,</span>
<span class="keyword">this</span><span class="special">,</span> <span class="identifier">asio</span><span class="special">::</span><span class="identifier">placeholders</span><span class="special">::</span><span class="identifier">error</span><span class="special">,</span>
<span class="identifier">asio</span><span class="special">::</span><span class="identifier">placeholders</span><span class="special">::</span><span class="identifier">results</span><span class="special">));</span>
</pre>
<p>
Using <a class="link" href="use_future.html" title="use_future">use_future</a> as a resolve
token:
</p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">future</span><span class="special">&lt;</span><span class="identifier">asio</span><span class="special">::</span><span class="identifier">ip</span><span class="special">::</span><span class="identifier">tcp</span><span class="special">::</span><span class="identifier">resolver</span><span class="special">::</span><span class="identifier">results_type</span><span class="special">&gt;</span> <span class="identifier">f</span> <span class="special">=</span>
<span class="identifier">resolver</span><span class="special">.</span><span class="identifier">async_resolve</span><span class="special">(...,</span> <span class="identifier">asio</span><span class="special">::</span><span class="identifier">use_future</span><span class="special">);</span>
<span class="special">...</span>
<span class="keyword">try</span>
<span class="special">{</span>
<span class="identifier">asio</span><span class="special">::</span><span class="identifier">ip</span><span class="special">::</span><span class="identifier">tcp</span><span class="special">::</span><span class="identifier">resolver</span><span class="special">::</span><span class="identifier">results_type</span> <span class="identifier">r</span> <span class="special">=</span> <span class="identifier">f</span><span class="special">.</span><span class="identifier">get</span><span class="special">();</span>
<span class="special">...</span>
<span class="special">}</span>
<span class="keyword">catch</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">system_error</span><span class="special">&amp;</span> <span class="identifier">e</span><span class="special">)</span>
<span class="special">{</span>
<span class="special">...</span>
<span class="special">}</span>
</pre>
<p>
Using <a class="link" href="use_awaitable.html" title="use_awaitable">use_awaitable</a> as
a resolve token:
</p>
<pre class="programlisting"><span class="identifier">asio</span><span class="special">::</span><span class="identifier">awaitable</span><span class="special">&lt;</span><span class="keyword">void</span><span class="special">&gt;</span> <span class="identifier">my_coroutine</span><span class="special">()</span>
<span class="special">{</span>
<span class="keyword">try</span>
<span class="special">{</span>
<span class="special">...</span>
<span class="identifier">asio</span><span class="special">::</span><span class="identifier">ip</span><span class="special">::</span><span class="identifier">tcp</span><span class="special">::</span><span class="identifier">resolver</span><span class="special">::</span><span class="identifier">results_type</span> <span class="identifier">r</span> <span class="special">=</span>
<span class="identifier">co_await</span> <span class="identifier">resolver</span><span class="special">.</span><span class="identifier">async_resolve</span><span class="special">(</span>
<span class="special">...,</span> <span class="identifier">asio</span><span class="special">::</span><span class="identifier">use_awaitable</span><span class="special">);</span>
<span class="special">...</span>
<span class="special">}</span>
<span class="keyword">catch</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">system_error</span><span class="special">&amp;</span> <span class="identifier">e</span><span class="special">)</span>
<span class="special">{</span>
<span class="special">...</span>
<span class="special">}</span>
<span class="special">}</span>
</pre>
</div>
<div class="copyright-footer">Copyright © 2003-2023 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>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="ResolveHandler.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>