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