Insane_DNS/libraries/asio-1.28.1/doc/asio/reference/experimental__basic_channel...

396 lines
20 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>experimental::basic_channel</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="experimental__awaitable_operators__operator_pipe__pipe_/overload6.html" title="experimental::awaitable_operators::operator|| (6 of 6 overloads)">
<link rel="next" href="experimental__basic_channel/async_receive.html" title="experimental::basic_channel::async_receive">
<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="experimental__awaitable_operators__operator_pipe__pipe_/overload6.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="experimental__basic_channel/async_receive.html"><img src="../../next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="asio.reference.experimental__basic_channel"></a><a class="link" href="experimental__basic_channel.html" title="experimental::basic_channel">experimental::basic_channel</a>
</h3></div></div></div>
<p>
<a class="indexterm" name="asio.indexterm.experimental__basic_channel"></a>
</p>
<p>
A channel for messages.
</p>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span>
<span class="keyword">typename</span> <a class="link" href="Executor1.html" title="Executor requirements">Executor</a><span class="special">,</span>
<span class="keyword">typename</span> <span class="identifier">Traits</span><span class="special">,</span>
<span class="keyword">typename</span><span class="special">...</span> <span class="identifier">Signatures</span><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">basic_channel</span>
</pre>
<h5>
<a name="asio.reference.experimental__basic_channel.h0"></a>
<span><a name="asio.reference.experimental__basic_channel.types"></a></span><a class="link" href="experimental__basic_channel.html#asio.reference.experimental__basic_channel.types">Types</a>
</h5>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Name
</p>
</th>
<th>
<p>
Description
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
<a class="link" href="experimental__basic_channel__rebind_executor.html" title="experimental::basic_channel::rebind_executor"><span class="bold"><strong>rebind_executor</strong></span></a>
</p>
</td>
<td>
<p>
Rebinds the channel type to another executor.
</p>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="experimental__basic_channel/executor_type.html" title="experimental::basic_channel::executor_type"><span class="bold"><strong>executor_type</strong></span></a>
</p>
</td>
<td>
<p>
The type of the executor associated with the channel.
</p>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="experimental__basic_channel/traits_type.html" title="experimental::basic_channel::traits_type"><span class="bold"><strong>traits_type</strong></span></a>
</p>
</td>
<td>
<p>
The traits type associated with the channel.
</p>
</td>
</tr>
</tbody>
</table></div>
<h5>
<a name="asio.reference.experimental__basic_channel.h1"></a>
<span><a name="asio.reference.experimental__basic_channel.member_functions"></a></span><a class="link" href="experimental__basic_channel.html#asio.reference.experimental__basic_channel.member_functions">Member
Functions</a>
</h5>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Name
</p>
</th>
<th>
<p>
Description
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
<a class="link" href="experimental__basic_channel/async_receive.html" title="experimental::basic_channel::async_receive"><span class="bold"><strong>async_receive</strong></span></a>
</p>
</td>
<td>
<p>
Asynchronously receive a message.
</p>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="experimental__basic_channel/async_send.html" title="experimental::basic_channel::async_send"><span class="bold"><strong>async_send</strong></span></a>
</p>
</td>
<td>
<p>
Asynchronously send a message.
</p>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="experimental__basic_channel/basic_channel.html" title="experimental::basic_channel::basic_channel"><span class="bold"><strong>basic_channel</strong></span></a> <span class="silver">[constructor]</span>
</p>
</td>
<td>
<p>
Construct a basic_channel. <br> <span class="silver"></span><br> Construct and open a basic_channel.
<br> <span class="silver"></span><br> Move-construct a basic_channel from another.
</p>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="experimental__basic_channel/cancel.html" title="experimental::basic_channel::cancel"><span class="bold"><strong>cancel</strong></span></a>
</p>
</td>
<td>
<p>
Cancel all asynchronous operations waiting on the channel.
</p>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="experimental__basic_channel/capacity.html" title="experimental::basic_channel::capacity"><span class="bold"><strong>capacity</strong></span></a>
</p>
</td>
<td>
<p>
Get the capacity of the channel's buffer.
</p>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="experimental__basic_channel/close.html" title="experimental::basic_channel::close"><span class="bold"><strong>close</strong></span></a>
</p>
</td>
<td>
<p>
Close the channel.
</p>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="experimental__basic_channel/get_executor.html" title="experimental::basic_channel::get_executor"><span class="bold"><strong>get_executor</strong></span></a>
</p>
</td>
<td>
<p>
Get the executor associated with the object.
</p>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="experimental__basic_channel/is_open.html" title="experimental::basic_channel::is_open"><span class="bold"><strong>is_open</strong></span></a>
</p>
</td>
<td>
<p>
Determine whether the channel is open.
</p>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="experimental__basic_channel/operator_eq_.html" title="experimental::basic_channel::operator="><span class="bold"><strong>operator=</strong></span></a>
</p>
</td>
<td>
<p>
Move-assign a basic_channel from another.
</p>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="experimental__basic_channel/ready.html" title="experimental::basic_channel::ready"><span class="bold"><strong>ready</strong></span></a>
</p>
</td>
<td>
<p>
Determine whether a message can be received without blocking.
</p>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="experimental__basic_channel/reset.html" title="experimental::basic_channel::reset"><span class="bold"><strong>reset</strong></span></a>
</p>
</td>
<td>
<p>
Reset the channel to its initial state.
</p>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="experimental__basic_channel/try_receive.html" title="experimental::basic_channel::try_receive"><span class="bold"><strong>try_receive</strong></span></a>
</p>
</td>
<td>
<p>
Try to receive a message without blocking.
</p>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="experimental__basic_channel/try_send.html" title="experimental::basic_channel::try_send"><span class="bold"><strong>try_send</strong></span></a>
</p>
</td>
<td>
<p>
Try to send a message without blocking.
</p>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="experimental__basic_channel/try_send_n.html" title="experimental::basic_channel::try_send_n"><span class="bold"><strong>try_send_n</strong></span></a>
</p>
</td>
<td>
<p>
Try to send a number of messages without blocking.
</p>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="experimental__basic_channel/_basic_channel.html" title="experimental::basic_channel::~basic_channel"><span class="bold"><strong>~basic_channel</strong></span></a> <span class="silver">[destructor]</span>
</p>
</td>
<td>
<p>
Destructor.
</p>
</td>
</tr>
</tbody>
</table></div>
<p>
The <a class="link" href="experimental__basic_channel.html" title="experimental::basic_channel"><code class="computeroutput"><span class="identifier">experimental</span><span class="special">::</span><span class="identifier">basic_channel</span></code></a> class template is
used for sending messages between different parts of the same application.
A <span class="emphasis"><em>message</em></span> is defined as a collection of arguments to
be passed to a completion handler, and the set of messages supported by a
channel is specified by its <code class="computeroutput"><span class="identifier">Traits</span></code>
and <code class="computeroutput"><span class="identifier">Signatures</span><span class="special">...</span></code>
template parameters. Messages may be sent and received using asynchronous
or non-blocking synchronous operations.
</p>
<p>
Unless customising the traits, applications will typically use the <code class="computeroutput"><span class="identifier">experimental</span><span class="special">::</span><span class="identifier">channel</span></code> alias template. For example:
</p>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">send_loop</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span><span class="special">,</span> <span class="identifier">steady_timer</span><span class="special">&amp;</span> <span class="identifier">timer</span><span class="special">,</span>
<span class="identifier">channel</span><span class="special">&lt;</span><span class="keyword">void</span><span class="special">(</span><span class="identifier">error_code</span><span class="special">,</span> <span class="keyword">int</span><span class="special">)&gt;&amp;</span> <span class="identifier">ch</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">if</span> <span class="special">(</span><span class="identifier">i</span> <span class="special">&lt;</span> <span class="number">10</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">timer</span><span class="special">.</span><span class="identifier">expires_after</span><span class="special">(</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">seconds</span><span class="special">(</span><span class="number">1</span><span class="special">));</span>
<span class="identifier">timer</span><span class="special">.</span><span class="identifier">async_wait</span><span class="special">(</span>
<span class="special">[</span><span class="identifier">i</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">timer</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">ch</span><span class="special">](</span><span class="identifier">error_code</span> <span class="identifier">error</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">if</span> <span class="special">(!</span><span class="identifier">error</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">ch</span><span class="special">.</span><span class="identifier">async_send</span><span class="special">(</span><span class="identifier">error_code</span><span class="special">(),</span> <span class="identifier">i</span><span class="special">,</span>
<span class="special">[</span><span class="identifier">i</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">timer</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">ch</span><span class="special">](</span><span class="identifier">error_code</span> <span class="identifier">error</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">if</span> <span class="special">(!</span><span class="identifier">error</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">send_loop</span><span class="special">(</span><span class="identifier">i</span> <span class="special">+</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">timer</span><span class="special">,</span> <span class="identifier">ch</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>
<span class="keyword">else</span>
<span class="special">{</span>
<span class="identifier">ch</span><span class="special">.</span><span class="identifier">close</span><span class="special">();</span>
<span class="special">}</span>
<span class="special">}</span>
<span class="keyword">void</span> <span class="identifier">receive_loop</span><span class="special">(</span><span class="identifier">channel</span><span class="special">&lt;</span><span class="keyword">void</span><span class="special">(</span><span class="identifier">error_code</span><span class="special">,</span> <span class="keyword">int</span><span class="special">)&gt;&amp;</span> <span class="identifier">ch</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">ch</span><span class="special">.</span><span class="identifier">async_receive</span><span class="special">(</span>
<span class="special">[&amp;</span><span class="identifier">ch</span><span class="special">](</span><span class="identifier">error_code</span> <span class="identifier">error</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">i</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">if</span> <span class="special">(!</span><span class="identifier">error</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"Received "</span> <span class="special">&lt;&lt;</span> <span class="identifier">i</span> <span class="special">&lt;&lt;</span> <span class="string">"\n"</span><span class="special">;</span>
<span class="identifier">receive_loop</span><span class="special">(</span><span class="identifier">ch</span><span class="special">);</span>
<span class="special">}</span>
<span class="special">});</span>
<span class="special">}</span>
</pre>
<h5>
<a name="asio.reference.experimental__basic_channel.h2"></a>
<span><a name="asio.reference.experimental__basic_channel.thread_safety"></a></span><a class="link" href="experimental__basic_channel.html#asio.reference.experimental__basic_channel.thread_safety">Thread
Safety</a>
</h5>
<p>
<span class="emphasis"><em>Distinct</em></span> <span class="emphasis"><em>objects:</em></span> Safe.
</p>
<p>
<span class="emphasis"><em>Shared</em></span> <span class="emphasis"><em>objects:</em></span> Unsafe.
</p>
<p>
The <a class="link" href="experimental__basic_channel.html" title="experimental::basic_channel"><code class="computeroutput"><span class="identifier">experimental</span><span class="special">::</span><span class="identifier">basic_channel</span></code></a> class template is
not thread-safe, and would typically be used for passing messages between
application code that runs on the same thread or in the same strand. Consider
using <a class="link" href="experimental__basic_concurrent_channel.html" title="experimental::basic_concurrent_channel"><code class="computeroutput"><span class="identifier">experimental</span><span class="special">::</span><span class="identifier">basic_concurrent_channel</span></code></a>, and its
alias template <code class="computeroutput"><span class="identifier">experimental</span><span class="special">::</span><span class="identifier">concurrent_channel</span></code>,
to pass messages between code running in different threads.
</p>
<h5>
<a name="asio.reference.experimental__basic_channel.h3"></a>
<span><a name="asio.reference.experimental__basic_channel.requirements"></a></span><a class="link" href="experimental__basic_channel.html#asio.reference.experimental__basic_channel.requirements">Requirements</a>
</h5>
<p>
<span class="emphasis"><em>Header: </em></span><code class="literal">asio/experimental/basic_channel.hpp</code>
</p>
<p>
<span class="emphasis"><em>Convenience header: </em></span>None
</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="experimental__awaitable_operators__operator_pipe__pipe_/overload6.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="experimental__basic_channel/async_receive.html"><img src="../../next.png" alt="Next"></a>
</div>
</body>
</html>