129 lines
12 KiB
HTML
129 lines
12 KiB
HTML
|
<html>
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||
|
<title>Move accept 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="MoveAcceptHandler.html" title="Move accept handler requirements">
|
||
|
<link rel="next" href="MutableBufferSequence.html" title="Mutable buffer sequence 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="MoveAcceptHandler.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="MutableBufferSequence.html"><img src="../../next.png" alt="Next"></a>
|
||
|
</div>
|
||
|
<div class="section">
|
||
|
<div class="titlepage"><div><div><h3 class="title">
|
||
|
<a name="asio.reference.MoveAcceptToken"></a><a class="link" href="MoveAcceptToken.html" title="Move accept token requirements">Move accept token requirements</a>
|
||
|
</h3></div></div></div>
|
||
|
<p>
|
||
|
A move accept 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="keyword">typename</span> <span class="identifier">Protocol</span><span class="special">::</span><span class="identifier">socket</span><span class="special">)</span></code>
|
||
|
or 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="keyword">typename</span> <span class="identifier">Protocol</span><span class="special">::</span><span class="identifier">socket</span><span class="special">::</span><span class="keyword">template</span> <span class="identifier">rebind_executor</span><span class="special"><</span><span class="identifier">Executor</span><span class="special">>::</span><span class="identifier">other</span><span class="special">)</span></code>, for the type <code class="computeroutput"><span class="identifier">Protocol</span></code>
|
||
|
of the acceptor class template.
|
||
|
</p>
|
||
|
<h5>
|
||
|
<a name="asio.reference.MoveAcceptToken.h0"></a>
|
||
|
<span><a name="asio.reference.MoveAcceptToken.examples"></a></span><a class="link" href="MoveAcceptToken.html#asio.reference.MoveAcceptToken.examples">Examples</a>
|
||
|
</h5>
|
||
|
<p>
|
||
|
A free function as a move accept token:
|
||
|
</p>
|
||
|
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">accept_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">&</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">socket</span> <span class="identifier">s</span><span class="special">)</span>
|
||
|
<span class="special">{</span>
|
||
|
<span class="special">...</span>
|
||
|
<span class="special">}</span>
|
||
|
</pre>
|
||
|
<p>
|
||
|
A move accept token function object:
|
||
|
</p>
|
||
|
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">accept_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">&</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">socket</span> <span class="identifier">s</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 move accept token:
|
||
|
</p>
|
||
|
<pre class="programlisting"><span class="identifier">acceptor</span><span class="special">.</span><span class="identifier">async_accept</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">&</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">socket</span> <span class="identifier">s</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 move accept 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">accept_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">&</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">socket</span> <span class="identifier">socket</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_accept</span><span class="special">(...,</span>
|
||
|
<span class="identifier">std</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(&</span><span class="identifier">my_class</span><span class="special">::</span><span class="identifier">accept_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>
|
||
|
Using <a class="link" href="use_future.html" title="use_future">use_future</a> as a move
|
||
|
accept token:
|
||
|
</p>
|
||
|
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">future</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">socket</span><span class="special">></span> <span class="identifier">f</span> <span class="special">=</span>
|
||
|
<span class="identifier">acceptor</span><span class="special">.</span><span class="identifier">async_accept</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">socket</span> <span class="identifier">s</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">&</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 move accept token:
|
||
|
</p>
|
||
|
<pre class="programlisting"><span class="identifier">asio</span><span class="special">::</span><span class="identifier">awaitable</span><span class="special"><</span><span class="keyword">void</span><span class="special">></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">socket</span> <span class="identifier">s</span> <span class="special">=</span>
|
||
|
<span class="identifier">co_await</span> <span class="identifier">acceptor</span><span class="special">.</span><span class="identifier">async_accept</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">&</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="MoveAcceptHandler.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="MutableBufferSequence.html"><img src="../../next.png" alt="Next"></a>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|