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