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

86 lines
9.0 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Receiver concepts</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="ReadToken.html" title="Read token requirements">
<link rel="next" href="ResolveHandler.html" title="Resolve 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="ReadToken.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="ResolveHandler.html"><img src="../../next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="asio.reference.Receiver"></a><a class="link" href="Receiver.html" title="Receiver concepts">Receiver concepts</a>
</h3></div></div></div>
<p>
A receiver represents the continuation of an asynchronous operation. An asynchronous
operation may complete with a (possibly empty) set of values, an error, or
it may be cancelled. A receiver has three principal operations corresponding
to the three ways an asynchronous operation may complete: <code class="computeroutput"><span class="identifier">set_value</span></code>,
<code class="computeroutput"><span class="identifier">set_error</span></code>, and <code class="computeroutput"><span class="identifier">set_done</span></code>. These are collectively known
as a receivers <span class="emphasis"><em>completion-signal operations</em></span>.
</p>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">E</span> <span class="special">=</span> <span class="identifier">exception_ptr</span><span class="special">&gt;</span>
<span class="identifier">concept</span> <span class="identifier">receiver</span> <span class="special">=</span>
<span class="identifier">move_constructible</span><span class="special">&lt;</span><span class="identifier">remove_cvref_t</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;&gt;</span> <span class="special">&amp;&amp;</span>
<span class="identifier">constructible_from</span><span class="special">&lt;</span><span class="identifier">remove_cvref_t</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;,</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="special">&amp;&amp;</span>
<span class="identifier">requires</span><span class="special">(</span><span class="identifier">remove_cvref_t</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;&amp;&amp;</span> <span class="identifier">t</span><span class="special">,</span> <span class="identifier">E</span><span class="special">&amp;&amp;</span> <span class="identifier">e</span><span class="special">)</span> <span class="special">{</span>
<span class="special">{</span> <span class="identifier">execution</span><span class="special">::</span><span class="identifier">set_done</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">t</span><span class="special">))</span> <span class="special">}</span> <span class="keyword">noexcept</span><span class="special">;</span>
<span class="special">{</span> <span class="identifier">execution</span><span class="special">::</span><span class="identifier">set_error</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">t</span><span class="special">),</span> <span class="special">(</span><span class="identifier">E</span><span class="special">&amp;&amp;)</span> <span class="identifier">e</span><span class="special">)</span> <span class="special">}</span> <span class="keyword">noexcept</span><span class="special">;</span>
<span class="special">};</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span><span class="special">...</span> <span class="identifier">An</span><span class="special">&gt;</span>
<span class="identifier">concept</span> <span class="identifier">receiver_of</span> <span class="special">=</span>
<span class="identifier">receiver</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="special">&amp;&amp;</span>
<span class="identifier">requires</span><span class="special">(</span><span class="identifier">remove_cvref_t</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;&amp;&amp;</span> <span class="identifier">t</span><span class="special">,</span> <span class="identifier">An</span><span class="special">&amp;&amp;...</span> <span class="identifier">an</span><span class="special">)</span> <span class="special">{</span>
<span class="identifier">execution</span><span class="special">::</span><span class="identifier">set_value</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">t</span><span class="special">),</span> <span class="special">(</span><span class="identifier">An</span><span class="special">&amp;&amp;)</span> <span class="identifier">an</span><span class="special">...);</span>
<span class="special">};</span>
</pre>
<p>
The receivers completion-signal operations have semantic requirements
that are collectively known as the <span class="emphasis"><em>receiver contract</em></span>,
described below:
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
None of a receivers completion-signal operations shall be invoked
before <code class="computeroutput"><span class="identifier">execution</span><span class="special">::</span><span class="identifier">start</span></code> has been called on the operation
state object that was returned by <code class="computeroutput"><span class="identifier">execution</span><span class="special">::</span><span class="identifier">connect</span></code>
to connect that receiver to a sender.
</li>
<li class="listitem">
Once <code class="computeroutput"><span class="identifier">execution</span><span class="special">::</span><span class="identifier">start</span></code> has been called on the operation
state object, exactly one of the receivers completion-signal operations
shall complete non-exceptionally before the receiver is destroyed.
</li>
<li class="listitem">
If <code class="computeroutput"><span class="identifier">execution</span><span class="special">::</span><span class="identifier">set_value</span></code> exits with an exception,
it is still valid to call <code class="computeroutput"><span class="identifier">execution</span><span class="special">::</span><span class="identifier">set_error</span></code>
or <code class="computeroutput"><span class="identifier">execution</span><span class="special">::</span><span class="identifier">set_done</span></code> on the receiver.
</li>
</ul></div>
<p>
Once one of a receivers completion-signal operations has completed non-exceptionally,
the receiver contract has been satisfied.
</p>
</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="ReadToken.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="ResolveHandler.html"><img src="../../next.png" alt="Next"></a>
</div>
</body>
</html>