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

150 lines
14 KiB
HTML
Raw 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>Iterator connect 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="IteratorConnectHandler.html" title="Iterator connect handler requirements">
<link rel="next" href="LegacyCompletionHandler.html" title="Legacy completion handler requirements">
<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="IteratorConnectHandler.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="LegacyCompletionHandler.html"><img src="../../next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="asio.reference.IteratorConnectToken"></a><a class="link" href="IteratorConnectToken.html" title="Iterator connect token requirements">Iterator connect
token requirements</a>
</h3></div></div></div>
<p>
An iterator connect 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">Iterator</span><span class="special">)</span></code>, where the type <code class="computeroutput"><span class="identifier">Iterator</span></code>
is used in the corresponding <code class="computeroutput"><span class="identifier">async_connect</span><span class="special">()</span></code> function.
</p>
<h5>
<a name="asio.reference.IteratorConnectToken.h0"></a>
<span><a name="asio.reference.IteratorConnectToken.examples"></a></span><a class="link" href="IteratorConnectToken.html#asio.reference.IteratorConnectToken.examples">Examples</a>
</h5>
<p>
A free function as an iterator connect token:
</p>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">connect_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">iterator</span> <span class="identifier">iterator</span><span class="special">)</span>
<span class="special">{</span>
<span class="special">...</span>
<span class="special">}</span>
</pre>
<p>
An iterator connect token function object:
</p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">connect_handler</span>
<span class="special">{</span>
<span class="special">...</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Iterator</span><span class="special">&gt;</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">Iterator</span> <span class="identifier">iterator</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 an iterator connect token:
</p>
<pre class="programlisting"><span class="identifier">asio</span><span class="special">::</span><span class="identifier">async_connect</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">iterator</span> <span class="identifier">iterator</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 an iterator connect 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">connect_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">iterator</span> <span class="identifier">iterator</span><span class="special">)</span>
<span class="special">{</span>
<span class="special">...</span>
<span class="special">}</span>
<span class="special">...</span>
<span class="identifier">asio</span><span class="special">::</span><span class="identifier">async_connect</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">connect_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 an iterator connect 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">connect_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">iterator</span> <span class="identifier">iterator</span><span class="special">)</span>
<span class="special">{</span>
<span class="special">...</span>
<span class="special">}</span>
<span class="special">...</span>
<span class="identifier">asio</span><span class="special">::</span><span class="identifier">async_connect</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">connect_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">iterator</span><span class="special">));</span>
</pre>
<p>
Using <a class="link" href="use_future.html" title="use_future">use_future</a> as an iterator
connect 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">iterator</span><span class="special">&gt;</span> <span class="identifier">f</span> <span class="special">=</span>
<span class="identifier">asio</span><span class="special">::</span><span class="identifier">async_connect</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">iterator</span> <span class="identifier">i</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
an iterator connect 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">iterator</span> <span class="identifier">i</span> <span class="special">=</span>
<span class="identifier">co_await</span> <span class="identifier">asio</span><span class="special">::</span><span class="identifier">async_connect</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="IteratorConnectHandler.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="LegacyCompletionHandler.html"><img src="../../next.png" alt="Next"></a>
</div>
</body>
</html>