Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / beast / doc / html / beast / ref / boost__beast__basic_stream__rebind_executor / other.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>basic_stream::rebind_executor::other</title>
5 <link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7 <link rel="home" href="../../../index.html" title="Chapter&#160;1.&#160;Boost.Beast">
8 <link rel="up" href="../boost__beast__basic_stream__rebind_executor.html" title="basic_stream::rebind_executor">
9 <link rel="prev" href="../boost__beast__basic_stream__rebind_executor.html" title="basic_stream::rebind_executor">
10 <link rel="next" href="../boost__beast__basic_stream__timeout_handler.html" title="basic_stream::timeout_handler">
11 </head>
12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13 <table cellpadding="2" width="100%"><tr>
14 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
15 <td align="center"><a href="../../../../../../../index.html">Home</a></td>
16 <td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
17 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19 <td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
20 </tr></table>
21 <hr>
22 <div class="spirit-nav">
23 <a accesskey="p" href="../boost__beast__basic_stream__rebind_executor.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../boost__beast__basic_stream__rebind_executor.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../boost__beast__basic_stream__timeout_handler.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
24 </div>
25 <div class="section">
26 <div class="titlepage"><div><div><h5 class="title">
27 <a name="beast.ref.boost__beast__basic_stream__rebind_executor.other"></a><a class="link" href="other.html" title="basic_stream::rebind_executor::other">basic_stream::rebind_executor::other</a>
28 </h5></div></div></div>
29 <p>
30           <a class="indexterm" name="idm45873514528736"></a>
31 The stream type when rebound to the specified
32           executor.
33         </p>
34 <h6>
35 <a name="beast.ref.boost__beast__basic_stream__rebind_executor.other.h0"></a>
36           <span class="phrase"><a name="beast.ref.boost__beast__basic_stream__rebind_executor.other.synopsis"></a></span><a class="link" href="other.html#beast.ref.boost__beast__basic_stream__rebind_executor.other.synopsis">Synopsis</a>
37         </h6>
38 <pre class="programlisting"><span class="keyword">using</span> <span class="identifier">other</span> <span class="special">=</span> <span class="identifier">basic_stream</span><span class="special">&lt;</span> <span class="identifier">Protocol</span><span class="special">,</span> <span class="identifier">Executor1</span><span class="special">,</span> <span class="identifier">RatePolicy</span> <span class="special">&gt;;</span>
39 </pre>
40 <h6>
41 <a name="beast.ref.boost__beast__basic_stream__rebind_executor.other.h1"></a>
42           <span class="phrase"><a name="beast.ref.boost__beast__basic_stream__rebind_executor.other.types"></a></span><a class="link" href="other.html#beast.ref.boost__beast__basic_stream__rebind_executor.other.types">Types</a>
43         </h6>
44 <div class="informaltable"><table class="table">
45 <colgroup>
46 <col>
47 <col>
48 </colgroup>
49 <thead><tr>
50 <th>
51                   <p>
52                     Name
53                   </p>
54                 </th>
55 <th>
56                   <p>
57                     Description
58                   </p>
59                 </th>
60 </tr></thead>
61 <tbody>
62 <tr>
63 <td>
64                   <p>
65                     <a class="link" href="../boost__beast__basic_stream__rebind_executor.html" title="basic_stream::rebind_executor"><span class="bold"><strong>rebind_executor</strong></span></a>
66                   </p>
67                 </td>
68 <td>
69                   <p>
70                     Rebinds the stream type to another executor.
71                   </p>
72                 </td>
73 </tr>
74 <tr>
75 <td>
76                   <p>
77                     <a class="link" href="../boost__beast__basic_stream/endpoint_type.html" title="basic_stream::endpoint_type"><span class="bold"><strong>endpoint_type</strong></span></a>
78                   </p>
79                 </td>
80 <td>
81                   <p>
82                     The endpoint type.
83                   </p>
84                 </td>
85 </tr>
86 <tr>
87 <td>
88                   <p>
89                     <a class="link" href="../boost__beast__basic_stream/executor_type.html" title="basic_stream::executor_type"><span class="bold"><strong>executor_type</strong></span></a>
90                   </p>
91                 </td>
92 <td>
93                   <p>
94                     The type of the executor associated with the stream.
95                   </p>
96                 </td>
97 </tr>
98 <tr>
99 <td>
100                   <p>
101                     <a class="link" href="../boost__beast__basic_stream/protocol_type.html" title="basic_stream::protocol_type"><span class="bold"><strong>protocol_type</strong></span></a>
102                   </p>
103                 </td>
104 <td>
105                   <p>
106                     The protocol type.
107                   </p>
108                 </td>
109 </tr>
110 <tr>
111 <td>
112                   <p>
113                     <a class="link" href="../boost__beast__basic_stream/socket_type.html" title="basic_stream::socket_type"><span class="bold"><strong>socket_type</strong></span></a>
114                   </p>
115                 </td>
116 <td>
117                   <p>
118                     The type of the underlying socket.
119                   </p>
120                 </td>
121 </tr>
122 </tbody>
123 </table></div>
124 <h6>
125 <a name="beast.ref.boost__beast__basic_stream__rebind_executor.other.h2"></a>
126           <span class="phrase"><a name="beast.ref.boost__beast__basic_stream__rebind_executor.other.member_functions"></a></span><a class="link" href="other.html#beast.ref.boost__beast__basic_stream__rebind_executor.other.member_functions">Member
127           Functions</a>
128         </h6>
129 <div class="informaltable"><table class="table">
130 <colgroup>
131 <col>
132 <col>
133 </colgroup>
134 <thead><tr>
135 <th>
136                   <p>
137                     Name
138                   </p>
139                 </th>
140 <th>
141                   <p>
142                     Description
143                   </p>
144                 </th>
145 </tr></thead>
146 <tbody>
147 <tr>
148 <td>
149                   <p>
150                     <a class="link" href="../boost__beast__basic_stream/async_connect.html" title="basic_stream::async_connect"><span class="bold"><strong>async_connect</strong></span></a>
151                   </p>
152                 </td>
153 <td>
154                   <p>
155                     Connect the stream to the specified endpoint asynchronously.
156                   </p>
157                   <p>
158                     Establishes a connection by trying each endpoint in a sequence
159                     asynchronously.
160                   </p>
161                 </td>
162 </tr>
163 <tr>
164 <td>
165                   <p>
166                     <a class="link" href="../boost__beast__basic_stream/async_read_some.html" title="basic_stream::async_read_some"><span class="bold"><strong>async_read_some</strong></span></a>
167                   </p>
168                 </td>
169 <td>
170                   <p>
171                     Read some data asynchronously.
172                   </p>
173                 </td>
174 </tr>
175 <tr>
176 <td>
177                   <p>
178                     <a class="link" href="../boost__beast__basic_stream/async_write_some.html" title="basic_stream::async_write_some"><span class="bold"><strong>async_write_some</strong></span></a>
179                   </p>
180                 </td>
181 <td>
182                   <p>
183                     Write some data asynchronously.
184                   </p>
185                 </td>
186 </tr>
187 <tr>
188 <td>
189                   <p>
190                     <a class="link" href="../boost__beast__basic_stream/basic_stream.html" title="basic_stream::basic_stream"><span class="bold"><strong>basic_stream</strong></span></a>
191                   </p>
192                 </td>
193 <td>
194                   <p>
195                     Constructor.
196                   </p>
197                   <p>
198                     Move constructor.
199                   </p>
200                 </td>
201 </tr>
202 <tr>
203 <td>
204                   <p>
205                     <a class="link" href="../boost__beast__basic_stream/cancel.html" title="basic_stream::cancel"><span class="bold"><strong>cancel</strong></span></a>
206                   </p>
207                 </td>
208 <td>
209                   <p>
210                     Cancel all asynchronous operations associated with the socket.
211                   </p>
212                 </td>
213 </tr>
214 <tr>
215 <td>
216                   <p>
217                     <a class="link" href="../boost__beast__basic_stream/close.html" title="basic_stream::close"><span class="bold"><strong>close</strong></span></a>
218                   </p>
219                 </td>
220 <td>
221                   <p>
222                     Close the timed stream.
223                   </p>
224                 </td>
225 </tr>
226 <tr>
227 <td>
228                   <p>
229                     <a class="link" href="../boost__beast__basic_stream/connect.html" title="basic_stream::connect"><span class="bold"><strong>connect</strong></span></a>
230                   </p>
231                 </td>
232 <td>
233                   <p>
234                     Connect the stream to the specified endpoint.
235                   </p>
236                   <p>
237                     Establishes a connection by trying each endpoint in a sequence.
238                   </p>
239                 </td>
240 </tr>
241 <tr>
242 <td>
243                   <p>
244                     <a class="link" href="../boost__beast__basic_stream/expires_after.html" title="basic_stream::expires_after"><span class="bold"><strong>expires_after</strong></span></a>
245                   </p>
246                 </td>
247 <td>
248                   <p>
249                     Set the timeout for the next logical operation.
250                   </p>
251                 </td>
252 </tr>
253 <tr>
254 <td>
255                   <p>
256                     <a class="link" href="../boost__beast__basic_stream/expires_at.html" title="basic_stream::expires_at"><span class="bold"><strong>expires_at</strong></span></a>
257                   </p>
258                 </td>
259 <td>
260                   <p>
261                     Set the timeout for the next logical operation.
262                   </p>
263                 </td>
264 </tr>
265 <tr>
266 <td>
267                   <p>
268                     <a class="link" href="../boost__beast__basic_stream/expires_never.html" title="basic_stream::expires_never"><span class="bold"><strong>expires_never</strong></span></a>
269                   </p>
270                 </td>
271 <td>
272                   <p>
273                     Disable the timeout for the next logical operation.
274                   </p>
275                 </td>
276 </tr>
277 <tr>
278 <td>
279                   <p>
280                     <a class="link" href="../boost__beast__basic_stream/get_executor.html" title="basic_stream::get_executor"><span class="bold"><strong>get_executor</strong></span></a>
281                   </p>
282                 </td>
283 <td>
284                   <p>
285                     Get the executor associated with the object.
286                   </p>
287                 </td>
288 </tr>
289 <tr>
290 <td>
291                   <p>
292                     <a class="link" href="../boost__beast__basic_stream/operator_eq_.html" title="basic_stream::operator="><span class="bold"><strong>operator=</strong></span></a>
293                   </p>
294                 </td>
295 <td>
296                   <p>
297                     Move assignment (deleted).
298                   </p>
299                 </td>
300 </tr>
301 <tr>
302 <td>
303                   <p>
304                     <a class="link" href="../boost__beast__basic_stream/rate_policy.html" title="basic_stream::rate_policy"><span class="bold"><strong>rate_policy</strong></span></a>
305                   </p>
306                 </td>
307 <td>
308                   <p>
309                     Returns the rate policy associated with the object.
310                   </p>
311                 </td>
312 </tr>
313 <tr>
314 <td>
315                   <p>
316                     <a class="link" href="../boost__beast__basic_stream/read_some.html" title="basic_stream::read_some"><span class="bold"><strong>read_some</strong></span></a>
317                   </p>
318                 </td>
319 <td>
320                   <p>
321                     Read some data.
322                   </p>
323                 </td>
324 </tr>
325 <tr>
326 <td>
327                   <p>
328                     <a class="link" href="../boost__beast__basic_stream/release_socket.html" title="basic_stream::release_socket"><span class="bold"><strong>release_socket</strong></span></a>
329                   </p>
330                 </td>
331 <td>
332                   <p>
333                     Release ownership of the underlying socket.
334                   </p>
335                 </td>
336 </tr>
337 <tr>
338 <td>
339                   <p>
340                     <a class="link" href="../boost__beast__basic_stream/socket.html" title="basic_stream::socket"><span class="bold"><strong>socket</strong></span></a>
341                   </p>
342                 </td>
343 <td>
344                   <p>
345                     Return a reference to the underlying socket.
346                   </p>
347                 </td>
348 </tr>
349 <tr>
350 <td>
351                   <p>
352                     <a class="link" href="../boost__beast__basic_stream/write_some.html" title="basic_stream::write_some"><span class="bold"><strong>write_some</strong></span></a>
353                   </p>
354                 </td>
355 <td>
356                   <p>
357                     Write some data.
358                   </p>
359                 </td>
360 </tr>
361 <tr>
362 <td>
363                   <p>
364                     <a class="link" href="../boost__beast__basic_stream/basic_stream_dtor_.html" title="basic_stream::~basic_stream"><span class="bold"><strong>~basic_stream</strong></span></a>
365                   </p>
366                 </td>
367 <td>
368                   <p>
369                     Destructor.
370                   </p>
371                 </td>
372 </tr>
373 </tbody>
374 </table></div>
375 <p>
376           This stream wraps a <code class="computeroutput"><span class="identifier">net</span><span class="special">::</span><span class="identifier">basic_stream_socket</span></code>
377           to provide the following features:
378         </p>
379 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
380 <li class="listitem">
381               An <span class="emphasis"><em>Executor</em></span> may be associated with the stream,
382               which will be used to invoke any completion handlers which do not already
383               have an associated executor. This achieves support for <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1322r0.html" target="_top">[P1322R0]
384               Networking TS enhancement to enable custom I/O executors</a>.
385             </li>
386 <li class="listitem">
387               Timeouts may be specified for each logical asynchronous operation performing
388               any reading, writing, or connecting.
389             </li>
390 <li class="listitem">
391               A <span class="emphasis"><em>RatePolicy</em></span> may be associated with the stream,
392               to implement rate limiting through the policy's interface.
393             </li>
394 </ul></div>
395 <p>
396           Although the stream supports multiple concurrent outstanding asynchronous
397           operations, the stream object is not thread-safe. The caller is responsible
398           for ensuring that the stream is accessed from only one thread at a time.
399           This includes the times when the stream, and its underlying socket, are
400           accessed by the networking implementation. To meet this thread safety requirement,
401           all asynchronous operations must be performed by the stream within the
402           same implicit strand (only one thread <code class="computeroutput"><span class="identifier">net</span><span class="special">::</span><span class="identifier">io_context</span><span class="special">::</span><span class="identifier">run</span></code>)
403           or within the same explicit strand, such as an instance of <code class="computeroutput"><span class="identifier">net</span><span class="special">::</span><span class="identifier">strand</span></code>. Completion handlers with explicit
404           associated executors (such as those arising from use of <code class="computeroutput"><span class="identifier">net</span><span class="special">::</span><span class="identifier">bind_executor</span></code>)
405           will be invoked by the stream using the associated executor. Otherwise,
406           the completion handler will be invoked by the executor associated with
407           the stream upon construction. The type of executor used with this stream
408           must meet the following requirements:
409         </p>
410 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
411               Function objects submitted to the executor shall never run concurrently
412               with each other.
413             </li></ul></div>
414 <p>
415           The executor type <code class="computeroutput"><span class="identifier">net</span><span class="special">::</span><span class="identifier">strand</span></code> meets these requirements. Use
416           of a strand as the executor in the stream class template offers an additional
417           notational convenience: the strand does not need to be specified in each
418           individual initiating function call. Unlike other stream wrappers, the
419           underlying socket is accessed through the <a class="link" href="../boost__beast__basic_stream/socket.html" title="basic_stream::socket"><code class="computeroutput"><span class="identifier">basic_stream</span><span class="special">::</span><span class="identifier">socket</span></code></a> member function instead
420           of <code class="computeroutput"><span class="identifier">next_layer</span></code>. This causes
421           the <a class="link" href="../boost__beast__basic_stream.html" title="basic_stream"><code class="computeroutput"><span class="identifier">basic_stream</span></code></a> to be returned in
422           calls to <a class="link" href="../boost__beast__get_lowest_layer.html" title="get_lowest_layer"><code class="computeroutput"><span class="identifier">get_lowest_layer</span></code></a>.
423         </p>
424 <h6>
425 <a name="beast.ref.boost__beast__basic_stream__rebind_executor.other.h3"></a>
426           <span class="phrase"><a name="beast.ref.boost__beast__basic_stream__rebind_executor.other.usage"></a></span><a class="link" href="other.html#beast.ref.boost__beast__basic_stream__rebind_executor.other.usage">Usage</a>
427         </h6>
428 <p>
429           To use this stream declare an instance of the class. Then, before each
430           logical operation for which a timeout is desired, call <a class="link" href="../boost__beast__basic_stream/expires_after.html" title="basic_stream::expires_after"><code class="computeroutput"><span class="identifier">basic_stream</span><span class="special">::</span><span class="identifier">expires_after</span></code></a> with a duration,
431           or call <a class="link" href="../boost__beast__basic_stream/expires_at.html" title="basic_stream::expires_at"><code class="computeroutput"><span class="identifier">basic_stream</span><span class="special">::</span><span class="identifier">expires_at</span></code></a> with a time point.
432           Alternatively, call <a class="link" href="../boost__beast__basic_stream/expires_never.html" title="basic_stream::expires_never"><code class="computeroutput"><span class="identifier">basic_stream</span><span class="special">::</span><span class="identifier">expires_never</span></code></a> to disable the timeout
433           for subsequent logical operations. A logical operation is any series of
434           one or more direct or indirect calls to the timeout stream's asynchronous
435           read, asynchronous write, or asynchronous connect functions. When a timeout
436           is set and a mixed operation is performed (one that includes both reads
437           and writes, for example) the timeout applies to all of the intermediate
438           asynchronous operations used in the enclosing operation. This allows timeouts
439           to be applied to stream algorithms which were not written specifically
440           to allow for timeouts, when those algorithms are passed a timeout stream
441           with a timeout set. When a timeout occurs the socket will be closed, canceling
442           any pending I/O operations. The completion handlers for these canceled
443           operations will be invoked with the error <a class="link" href="../boost__beast__error.html" title="error"><code class="computeroutput"><span class="identifier">timeout</span></code></a>.
444         </p>
445 <h6>
446 <a name="beast.ref.boost__beast__basic_stream__rebind_executor.other.h4"></a>
447           <span class="phrase"><a name="beast.ref.boost__beast__basic_stream__rebind_executor.other.examples"></a></span><a class="link" href="other.html#beast.ref.boost__beast__basic_stream__rebind_executor.other.examples">Examples</a>
448         </h6>
449 <p>
450           This function reads an HTTP request with a timeout, then sends the HTTP
451           response with a different timeout.
452         </p>
453 <pre class="programlisting"><span class="keyword">void</span> <span class="identifier">process_http_1</span> <span class="special">(</span><span class="identifier">tcp_stream</span><span class="special">&amp;</span> <span class="identifier">stream</span><span class="special">,</span> <span class="identifier">net</span><span class="special">::</span><span class="identifier">yield_context</span> <span class="identifier">yield</span><span class="special">)</span>
454 <span class="special">{</span>
455     <span class="identifier">flat_buffer</span> <span class="identifier">buffer</span><span class="special">;</span>
456     <span class="identifier">http</span><span class="special">::</span><span class="identifier">request</span><span class="special">&lt;</span><span class="identifier">http</span><span class="special">::</span><span class="identifier">empty_body</span><span class="special">&gt;</span> <span class="identifier">req</span><span class="special">;</span>
457
458     <span class="comment">// Read the request, with a 15 second timeout</span>
459     <span class="identifier">stream</span><span class="special">.</span><span class="identifier">expires_after</span><span class="special">(</span><span class="identifier">std</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">15</span><span class="special">));</span>
460     <span class="identifier">http</span><span class="special">::</span><span class="identifier">async_read</span><span class="special">(</span><span class="identifier">stream</span><span class="special">,</span> <span class="identifier">buffer</span><span class="special">,</span> <span class="identifier">req</span><span class="special">,</span> <span class="identifier">yield</span><span class="special">);</span>
461
462     <span class="comment">// Calculate the response</span>
463     <span class="identifier">http</span><span class="special">::</span><span class="identifier">response</span><span class="special">&lt;</span><span class="identifier">http</span><span class="special">::</span><span class="identifier">string_body</span><span class="special">&gt;</span> <span class="identifier">res</span> <span class="special">=</span> <span class="identifier">make_response</span><span class="special">(</span><span class="identifier">req</span><span class="special">);</span>
464
465     <span class="comment">// Send the response, with a 30 second timeout.</span>
466     <span class="identifier">stream</span><span class="special">.</span><span class="identifier">expires_after</span> <span class="special">(</span><span class="identifier">std</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">30</span><span class="special">));</span>
467     <span class="identifier">http</span><span class="special">::</span><span class="identifier">async_write</span> <span class="special">(</span><span class="identifier">stream</span><span class="special">,</span> <span class="identifier">res</span><span class="special">,</span> <span class="identifier">yield</span><span class="special">);</span>
468 <span class="special">}</span>
469 </pre>
470 <p>
471           The example above could be expressed using a single timeout with a simple
472           modification. The function that follows first reads an HTTP request then
473           sends the HTTP response, with a single timeout that applies to the entire
474           combined operation of reading and writing:
475         </p>
476 <pre class="programlisting"><span class="keyword">void</span> <span class="identifier">process_http_2</span> <span class="special">(</span><span class="identifier">tcp_stream</span><span class="special">&amp;</span> <span class="identifier">stream</span><span class="special">,</span> <span class="identifier">net</span><span class="special">::</span><span class="identifier">yield_context</span> <span class="identifier">yield</span><span class="special">)</span>
477 <span class="special">{</span>
478     <span class="identifier">flat_buffer</span> <span class="identifier">buffer</span><span class="special">;</span>
479     <span class="identifier">http</span><span class="special">::</span><span class="identifier">request</span><span class="special">&lt;</span><span class="identifier">http</span><span class="special">::</span><span class="identifier">empty_body</span><span class="special">&gt;</span> <span class="identifier">req</span><span class="special">;</span>
480
481     <span class="comment">// Require that the read and write combined take no longer than 30 seconds</span>
482     <span class="identifier">stream</span><span class="special">.</span><span class="identifier">expires_after</span><span class="special">(</span><span class="identifier">std</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">30</span><span class="special">));</span>
483
484     <span class="identifier">http</span><span class="special">::</span><span class="identifier">async_read</span><span class="special">(</span><span class="identifier">stream</span><span class="special">,</span> <span class="identifier">buffer</span><span class="special">,</span> <span class="identifier">req</span><span class="special">,</span> <span class="identifier">yield</span><span class="special">);</span>
485
486     <span class="identifier">http</span><span class="special">::</span><span class="identifier">response</span><span class="special">&lt;</span><span class="identifier">http</span><span class="special">::</span><span class="identifier">string_body</span><span class="special">&gt;</span> <span class="identifier">res</span> <span class="special">=</span> <span class="identifier">make_response</span><span class="special">(</span><span class="identifier">req</span><span class="special">);</span>
487     <span class="identifier">http</span><span class="special">::</span><span class="identifier">async_write</span> <span class="special">(</span><span class="identifier">stream</span><span class="special">,</span> <span class="identifier">res</span><span class="special">,</span> <span class="identifier">yield</span><span class="special">);</span>
488 <span class="special">}</span>
489 </pre>
490 <p>
491           Some stream algorithms, such as <code class="computeroutput"><span class="identifier">ssl</span><span class="special">::</span><span class="identifier">stream</span><span class="special">::</span><span class="identifier">async_handshake</span></code>
492           perform both reads and writes. A timeout set before calling the initiating
493           function of such composite stream algorithms will apply to the entire composite
494           operation. For example, a timeout may be set on performing the SSL handshake
495           thusly:
496         </p>
497 <pre class="programlisting"><span class="keyword">void</span> <span class="identifier">do_ssl_handshake</span> <span class="special">(</span><span class="identifier">net</span><span class="special">::</span><span class="identifier">ssl</span><span class="special">::</span><span class="identifier">stream</span><span class="special">&lt;</span><span class="identifier">tcp_stream</span><span class="special">&gt;&amp;</span> <span class="identifier">stream</span><span class="special">,</span> <span class="identifier">net</span><span class="special">::</span><span class="identifier">yield_context</span> <span class="identifier">yield</span><span class="special">)</span>
498 <span class="special">{</span>
499     <span class="comment">// Require that the SSL handshake take no longer than 10 seconds</span>
500     <span class="identifier">stream</span><span class="special">.</span><span class="identifier">expires_after</span><span class="special">(</span><span class="identifier">std</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">10</span><span class="special">));</span>
501
502     <span class="identifier">stream</span><span class="special">.</span><span class="identifier">async_handshake</span><span class="special">(</span><span class="identifier">net</span><span class="special">::</span><span class="identifier">ssl</span><span class="special">::</span><span class="identifier">stream_base</span><span class="special">::</span><span class="identifier">client</span><span class="special">,</span> <span class="identifier">yield</span><span class="special">);</span>
503 <span class="special">}</span>
504 </pre>
505 <h6>
506 <a name="beast.ref.boost__beast__basic_stream__rebind_executor.other.h5"></a>
507           <span class="phrase"><a name="beast.ref.boost__beast__basic_stream__rebind_executor.other.blocking_i_o"></a></span><a class="link" href="other.html#beast.ref.boost__beast__basic_stream__rebind_executor.other.blocking_i_o">Blocking
508           I/O</a>
509         </h6>
510 <p>
511           Synchronous functions behave identically as that of the wrapped <code class="computeroutput"><span class="identifier">net</span><span class="special">::</span><span class="identifier">basic_stream_socket</span></code>. Timeouts are not
512           available when performing blocking calls.
513         </p>
514 <h6>
515 <a name="beast.ref.boost__beast__basic_stream__rebind_executor.other.h6"></a>
516           <span class="phrase"><a name="beast.ref.boost__beast__basic_stream__rebind_executor.other.template_parameters"></a></span><a class="link" href="other.html#beast.ref.boost__beast__basic_stream__rebind_executor.other.template_parameters">Template
517           Parameters</a>
518         </h6>
519 <div class="informaltable"><table class="table">
520 <colgroup>
521 <col>
522 <col>
523 </colgroup>
524 <thead><tr>
525 <th>
526                   <p>
527                     Type
528                   </p>
529                 </th>
530 <th>
531                   <p>
532                     Description
533                   </p>
534                 </th>
535 </tr></thead>
536 <tbody>
537 <tr>
538 <td>
539                   <p>
540                     <code class="computeroutput"><span class="identifier">Protocol</span></code>
541                   </p>
542                 </td>
543 <td>
544                   <p>
545                     A type meeting the requirements of <span class="emphasis"><em>Protocol</em></span>
546                     representing the protocol the protocol to use for the basic stream
547                     socket. A common choice is <code class="computeroutput"><span class="identifier">net</span><span class="special">::</span><span class="identifier">ip</span><span class="special">::</span><span class="identifier">tcp</span></code>.
548                   </p>
549                 </td>
550 </tr>
551 <tr>
552 <td>
553                   <p>
554                     <code class="computeroutput"><span class="identifier">Executor</span></code>
555                   </p>
556                 </td>
557 <td>
558                   <p>
559                     A type meeting the requirements of <span class="emphasis"><em>Executor</em></span>
560                     to be used for submitting all completion handlers which do not
561                     already have an associated executor. If this type is omitted,
562                     the default of <code class="computeroutput"><span class="identifier">net</span><span class="special">::</span><span class="identifier">executor</span></code>
563                     will be used.
564                   </p>
565                 </td>
566 </tr>
567 </tbody>
568 </table></div>
569 <h6>
570 <a name="beast.ref.boost__beast__basic_stream__rebind_executor.other.h7"></a>
571           <span class="phrase"><a name="beast.ref.boost__beast__basic_stream__rebind_executor.other.thread_safety"></a></span><a class="link" href="other.html#beast.ref.boost__beast__basic_stream__rebind_executor.other.thread_safety">Thread
572           Safety</a>
573         </h6>
574 <p>
575           <span class="emphasis"><em>Distinct objects</em></span>: Safe.
576         </p>
577 <p>
578           <span class="emphasis"><em>Shared objects</em></span>: Unsafe. The application must also
579           ensure that all asynchronous operations are performed within the same implicit
580           or explicit strand.
581         </p>
582 <h6>
583 <a name="beast.ref.boost__beast__basic_stream__rebind_executor.other.h8"></a>
584           <span class="phrase"><a name="beast.ref.boost__beast__basic_stream__rebind_executor.other.see_also"></a></span><a class="link" href="other.html#beast.ref.boost__beast__basic_stream__rebind_executor.other.see_also">See
585           Also</a>
586         </h6>
587 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
588               <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1322r0.html" target="_top">[P1322R0]
589               Networking TS enhancement to enable custom I/O executors</a>.
590             </li></ul></div>
591 <h6>
592 <a name="beast.ref.boost__beast__basic_stream__rebind_executor.other.h9"></a>
593           <span class="phrase"><a name="beast.ref.boost__beast__basic_stream__rebind_executor.other.description"></a></span><a class="link" href="other.html#beast.ref.boost__beast__basic_stream__rebind_executor.other.description">Description</a>
594         </h6>
595 </div>
596 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
597 <td align="left"></td>
598 <td align="right"><div class="copyright-footer">Copyright &#169; 2016-2019 Vinnie
599       Falco<p>
600         Distributed under the Boost Software License, Version 1.0. (See accompanying
601         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>)
602       </p>
603 </div></td>
604 </tr></table>
605 <hr>
606 <div class="spirit-nav">
607 <a accesskey="p" href="../boost__beast__basic_stream__rebind_executor.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../boost__beast__basic_stream__rebind_executor.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../boost__beast__basic_stream__timeout_handler.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
608 </div>
609 </body>
610 </html>