stream.hpp 101 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648
  1. //
  2. // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/beast
  8. //
  9. #ifndef BOOST_BEAST_WEBSOCKET_STREAM_HPP
  10. #define BOOST_BEAST_WEBSOCKET_STREAM_HPP
  11. #include <boost/beast/core/detail/config.hpp>
  12. #include <boost/beast/websocket/error.hpp>
  13. #include <boost/beast/websocket/option.hpp>
  14. #include <boost/beast/websocket/rfc6455.hpp>
  15. #include <boost/beast/websocket/stream_base.hpp>
  16. #include <boost/beast/websocket/stream_fwd.hpp>
  17. #include <boost/beast/websocket/detail/hybi13.hpp>
  18. #include <boost/beast/websocket/detail/impl_base.hpp>
  19. #include <boost/beast/websocket/detail/pmd_extension.hpp>
  20. #include <boost/beast/websocket/detail/prng.hpp>
  21. #include <boost/beast/core/role.hpp>
  22. #include <boost/beast/core/stream_traits.hpp>
  23. #include <boost/beast/core/string.hpp>
  24. #include <boost/beast/http/detail/type_traits.hpp>
  25. #include <boost/asio/async_result.hpp>
  26. #include <boost/asio/error.hpp>
  27. #include <boost/shared_ptr.hpp>
  28. #include <algorithm>
  29. #include <cstdint>
  30. #include <functional>
  31. #include <limits>
  32. #include <memory>
  33. #include <type_traits>
  34. #include <random>
  35. namespace boost {
  36. namespace beast {
  37. namespace websocket {
  38. /** The type of received control frame.
  39. Values of this type are passed to the control frame
  40. callback set using @ref stream::control_callback.
  41. */
  42. enum class frame_type
  43. {
  44. /// A close frame was received
  45. close,
  46. /// A ping frame was received
  47. ping,
  48. /// A pong frame was received
  49. pong
  50. };
  51. namespace detail {
  52. class frame_test;
  53. } // detail
  54. //--------------------------------------------------------------------
  55. /** Provides message-oriented functionality using WebSocket.
  56. The @ref stream class template provides asynchronous and blocking
  57. message-oriented functionality necessary for clients and servers
  58. to utilize the WebSocket protocol.
  59. For asynchronous operations, the application must ensure
  60. that they are are all performed within the same implicit
  61. or explicit strand.
  62. @par Thread Safety
  63. @e Distinct @e objects: Safe.@n
  64. @e Shared @e objects: Unsafe.
  65. The application must also ensure that all asynchronous
  66. operations are performed within the same implicit or explicit strand.
  67. @par Example
  68. To declare the @ref stream object with a @ref tcp_stream in a
  69. multi-threaded asynchronous program using a strand, you may write:
  70. @code
  71. websocket::stream<tcp_stream> ws{net::make_strand(ioc)};
  72. @endcode
  73. Alternatively, for a single-threaded or synchronous application
  74. you may write:
  75. @code
  76. websocket::stream<tcp_stream> ws(ioc);
  77. @endcode
  78. @tparam NextLayer The type representing the next layer, to which
  79. data will be read and written during operations. For synchronous
  80. operations, the type must support the <em>SyncStream</em> concept.
  81. For asynchronous operations, the type must support the
  82. <em>AsyncStream</em> concept.
  83. @tparam deflateSupported A `bool` indicating whether or not the
  84. stream will be capable of negotiating the permessage-deflate websocket
  85. extension. Note that even if this is set to `true`, the permessage
  86. deflate options (set by the caller at runtime) must still have the
  87. feature enabled for a successful negotiation to occur.
  88. @note A stream object must not be moved or destroyed while there
  89. are pending asynchronous operations associated with it.
  90. @par Concepts
  91. @li <em>AsyncStream</em>
  92. @li <em>DynamicBuffer</em>
  93. @li <em>SyncStream</em>
  94. @see
  95. @li <a href="https://tools.ietf.org/html/rfc6455#section-4.1">Websocket Opening Handshake Client Requirements (RFC6455)</a>
  96. @li <a href="https://tools.ietf.org/html/rfc6455#section-4.2">Websocket Opening Handshake Server Requirements (RFC6455)</a>
  97. @li <a href="https://tools.ietf.org/html/rfc6455#section-7.1.2">Websocket Closing Handshake (RFC6455)</a>
  98. @li <a href="https://tools.ietf.org/html/rfc6455#section-5.5.1">Websocket Close (RFC6455)</a>
  99. @li <a href="https://tools.ietf.org/html/rfc6455#section-5.5.2">WebSocket Ping (RFC6455)</a>
  100. @li <a href="https://tools.ietf.org/html/rfc6455#section-5.5.3">WebSocket Pong (RFC6455)</a>
  101. @li <a href="https://tools.ietf.org/html/rfc7230#section-5.4">Host field (RFC7230)</a>
  102. @li <a href="https://tools.ietf.org/html/rfc7230#section-3.1.1">request-target (RFC7230)</a>
  103. @li <a href="https://tools.ietf.org/html/rfc7230#section-5.3.1">origin-form (RFC7230)</a>
  104. */
  105. template<
  106. class NextLayer,
  107. bool deflateSupported>
  108. class stream
  109. #if ! BOOST_BEAST_DOXYGEN
  110. : private stream_base
  111. #endif
  112. {
  113. struct impl_type;
  114. boost::shared_ptr<impl_type> impl_;
  115. using time_point = typename
  116. std::chrono::steady_clock::time_point;
  117. using control_cb_type =
  118. std::function<void(frame_type, string_view)>;
  119. friend class close_test;
  120. friend class frame_test;
  121. friend class ping_test;
  122. friend class read2_test;
  123. friend class read3_test;
  124. friend class stream_test;
  125. friend class write_test;
  126. /* The read buffer has to be at least as large
  127. as the largest possible control frame including
  128. the frame header.
  129. */
  130. static std::size_t constexpr max_control_frame_size = 2 + 8 + 4 + 125;
  131. static std::size_t constexpr tcp_frame_size = 1536;
  132. static time_point never() noexcept
  133. {
  134. return (time_point::max)();
  135. }
  136. public:
  137. /// Indicates if the permessage-deflate extension is supported
  138. using is_deflate_supported =
  139. std::integral_constant<bool, deflateSupported>;
  140. /// The type of the next layer.
  141. using next_layer_type =
  142. typename std::remove_reference<NextLayer>::type;
  143. /// The type of the executor associated with the object.
  144. using executor_type =
  145. beast::executor_type<next_layer_type>;
  146. /** Destructor
  147. Destroys the stream and all associated resources.
  148. @note A stream object must not be destroyed while there
  149. are pending asynchronous operations associated with it.
  150. */
  151. ~stream();
  152. /** Constructor
  153. If `NextLayer` is move constructible, this function
  154. will move-construct a new stream from the existing stream.
  155. After the move, the only valid operation on the moved-from
  156. object is destruction.
  157. */
  158. stream(stream&&) = default;
  159. /// Move assignment (deleted)
  160. stream& operator=(stream&&) = delete;
  161. /** Constructor
  162. This constructor creates a websocket stream and initializes
  163. the next layer object.
  164. @throws Any exceptions thrown by the NextLayer constructor.
  165. @param args The arguments to be passed to initialize the
  166. next layer object. The arguments are forwarded to the next
  167. layer's constructor.
  168. */
  169. template<class... Args>
  170. explicit
  171. stream(Args&&... args);
  172. //--------------------------------------------------------------------------
  173. /** Get the executor associated with the object.
  174. This function may be used to obtain the executor object that the
  175. stream uses to dispatch handlers for asynchronous operations.
  176. @return A copy of the executor that stream will use to dispatch handlers.
  177. */
  178. executor_type
  179. get_executor() noexcept;
  180. /** Get a reference to the next layer
  181. This function returns a reference to the next layer
  182. in a stack of stream layers.
  183. @return A reference to the next layer in the stack of
  184. stream layers.
  185. */
  186. next_layer_type&
  187. next_layer() noexcept;
  188. /** Get a reference to the next layer
  189. This function returns a reference to the next layer in a
  190. stack of stream layers.
  191. @return A reference to the next layer in the stack of
  192. stream layers.
  193. */
  194. next_layer_type const&
  195. next_layer() const noexcept;
  196. //--------------------------------------------------------------------------
  197. //
  198. // Observers
  199. //
  200. //--------------------------------------------------------------------------
  201. /** Returns `true` if the stream is open.
  202. The stream is open after a successful handshake, and when
  203. no error has occurred.
  204. */
  205. bool
  206. is_open() const noexcept;
  207. /** Returns `true` if the latest message data indicates binary.
  208. This function informs the caller of whether the last
  209. received message frame represents a message with the
  210. binary opcode.
  211. If there is no last message frame, the return value is
  212. undefined.
  213. */
  214. bool
  215. got_binary() const noexcept;
  216. /** Returns `true` if the latest message data indicates text.
  217. This function informs the caller of whether the last
  218. received message frame represents a message with the
  219. text opcode.
  220. If there is no last message frame, the return value is
  221. undefined.
  222. */
  223. bool
  224. got_text() const
  225. {
  226. return ! got_binary();
  227. }
  228. /// Returns `true` if the last completed read finished the current message.
  229. bool
  230. is_message_done() const noexcept;
  231. /** Returns the close reason received from the remote peer.
  232. This is only valid after a read completes with error::closed.
  233. */
  234. close_reason const&
  235. reason() const noexcept;
  236. /** Returns a suggested maximum buffer size for the next call to read.
  237. This function returns a reasonable upper limit on the number
  238. of bytes for the size of the buffer passed in the next call
  239. to read. The number is determined by the state of the current
  240. frame and whether or not the permessage-deflate extension is
  241. enabled.
  242. @param initial_size A non-zero size representing the caller's
  243. desired buffer size for when there is no information which may
  244. be used to calculate a more specific value. For example, when
  245. reading the first frame header of a message.
  246. */
  247. std::size_t
  248. read_size_hint(
  249. std::size_t initial_size = +tcp_frame_size) const;
  250. /** Returns a suggested maximum buffer size for the next call to read.
  251. This function returns a reasonable upper limit on the number
  252. of bytes for the size of the buffer passed in the next call
  253. to read. The number is determined by the state of the current
  254. frame and whether or not the permessage-deflate extension is
  255. enabled.
  256. @param buffer The buffer which will be used for reading. The
  257. implementation will query the buffer to obtain the optimum
  258. size of a subsequent call to `buffer.prepare` based on the
  259. state of the current frame, if any.
  260. */
  261. template<class DynamicBuffer
  262. #if ! BOOST_BEAST_DOXYGEN
  263. , class = typename std::enable_if<
  264. ! std::is_integral<DynamicBuffer>::value>::type
  265. #endif
  266. >
  267. std::size_t
  268. read_size_hint(
  269. DynamicBuffer& buffer) const;
  270. //--------------------------------------------------------------------------
  271. //
  272. // Settings
  273. //
  274. //--------------------------------------------------------------------------
  275. #if BOOST_BEAST_DOXYGEN
  276. template<class Option>
  277. void
  278. get_option(Option& opt);
  279. template<class Option>
  280. void
  281. set_option(Option opt);
  282. #else
  283. void set_option(decorator opt);
  284. void get_option(timeout& opt);
  285. void set_option(timeout const& opt);
  286. #endif
  287. /** Set the permessage-deflate extension options
  288. @throws invalid_argument if `deflateSupported == false`, and either
  289. `client_enable` or `server_enable` is `true`.
  290. */
  291. void
  292. set_option(permessage_deflate const& o);
  293. /// Get the permessage-deflate extension options
  294. void
  295. get_option(permessage_deflate& o);
  296. /** Set the automatic fragmentation option.
  297. Determines if outgoing message payloads are broken up into
  298. multiple pieces.
  299. When the automatic fragmentation size is turned on, outgoing
  300. message payloads are broken up into multiple frames no larger
  301. than the write buffer size.
  302. The default setting is to fragment messages.
  303. @param value A `bool` indicating if auto fragmentation should be on.
  304. @par Example
  305. Setting the automatic fragmentation option:
  306. @code
  307. ws.auto_fragment(true);
  308. @endcode
  309. */
  310. void
  311. auto_fragment(bool value);
  312. /// Returns `true` if the automatic fragmentation option is set.
  313. bool
  314. auto_fragment() const;
  315. /** Set the binary message write option.
  316. This controls whether or not outgoing message opcodes
  317. are set to binary or text. The setting is only applied
  318. at the start when a caller begins a new message. Changing
  319. the opcode after a message is started will only take effect
  320. after the current message being sent is complete.
  321. The default setting is to send text messages.
  322. @param value `true` if outgoing messages should indicate
  323. binary, or `false` if they should indicate text.
  324. @par Example
  325. Setting the message type to binary.
  326. @code
  327. ws.binary(true);
  328. @endcode
  329. */
  330. void
  331. binary(bool value);
  332. /// Returns `true` if the binary message write option is set.
  333. bool
  334. binary() const;
  335. /** Set a callback to be invoked on each incoming control frame.
  336. Sets the callback to be invoked whenever a ping, pong,
  337. or close control frame is received during a call to one
  338. of the following functions:
  339. @li @ref beast::websocket::stream::read
  340. @li @ref beast::websocket::stream::read_some
  341. @li @ref beast::websocket::stream::async_read
  342. @li @ref beast::websocket::stream::async_read_some
  343. Unlike completion handlers, the callback will be invoked
  344. for each control frame during a call to any synchronous
  345. or asynchronous read function. The operation is passive,
  346. with no associated error code, and triggered by reads.
  347. For close frames, the close reason code may be obtained by
  348. calling the function @ref reason.
  349. @param cb The function object to call, which must be
  350. invocable with this equivalent signature:
  351. @code
  352. void
  353. callback(
  354. frame_type kind, // The type of frame
  355. string_view payload // The payload in the frame
  356. );
  357. @endcode
  358. The implementation type-erases the callback which may require
  359. a dynamic allocation. To prevent the possibility of a dynamic
  360. allocation, use `std::ref` to wrap the callback.
  361. If the read operation which receives the control frame is
  362. an asynchronous operation, the callback will be invoked using
  363. the same method as that used to invoke the final handler.
  364. @note Incoming ping and close frames are automatically
  365. handled. Pings are responded to with pongs, and a close frame
  366. is responded to with a close frame leading to the closure of
  367. the stream. It is not necessary to manually send pings, pongs,
  368. or close frames from inside the control callback.
  369. Attempting to manually send a close frame from inside the
  370. control callback after receiving a close frame will result
  371. in undefined behavior.
  372. */
  373. void
  374. control_callback(std::function<void(frame_type, string_view)> cb);
  375. /** Reset the control frame callback.
  376. This function removes any previously set control frame callback.
  377. */
  378. void
  379. control_callback();
  380. /** Set the maximum incoming message size option.
  381. Sets the largest permissible incoming message size. Message
  382. frame fields indicating a size that would bring the total
  383. message size over this limit will cause a protocol failure.
  384. The default setting is 16 megabytes. A value of zero indicates
  385. a limit of the maximum value of a `std::uint64_t`.
  386. @par Example
  387. Setting the maximum read message size.
  388. @code
  389. ws.read_message_max(65536);
  390. @endcode
  391. @param amount The limit on the size of incoming messages.
  392. */
  393. void
  394. read_message_max(std::size_t amount);
  395. /// Returns the maximum incoming message size setting.
  396. std::size_t
  397. read_message_max() const;
  398. /** Set whether the PRNG is cryptographically secure
  399. This controls whether or not the source of pseudo-random
  400. numbers used to produce the masks required by the WebSocket
  401. protocol are of cryptographic quality. When the setting is
  402. `true`, a strong algorithm is used which cannot be guessed
  403. by observing outputs. When the setting is `false`, a much
  404. faster algorithm is used.
  405. Masking is only performed by streams operating in the client
  406. mode. For streams operating in the server mode, this setting
  407. has no effect.
  408. By default, newly constructed streams use a secure PRNG.
  409. If the WebSocket stream is used with an encrypted SSL or TLS
  410. next layer, if it is known to the application that intermediate
  411. proxies are not vulnerable to cache poisoning, or if the
  412. application is designed such that an attacker cannot send
  413. arbitrary inputs to the stream interface, then the faster
  414. algorithm may be used.
  415. For more information please consult the WebSocket protocol RFC.
  416. @param value `true` if the PRNG algorithm should be
  417. cryptographically secure.
  418. */
  419. void
  420. secure_prng(bool value);
  421. /** Set the write buffer size option.
  422. Sets the size of the write buffer used by the implementation to
  423. send frames. The write buffer is needed when masking payload data
  424. in the client role, compressing frames, or auto-fragmenting message
  425. data.
  426. Lowering the size of the buffer can decrease the memory requirements
  427. for each connection, while increasing the size of the buffer can reduce
  428. the number of calls made to the next layer to write data.
  429. The default setting is 4096. The minimum value is 8.
  430. The write buffer size can only be changed when the stream is not
  431. open. Undefined behavior results if the option is modified after a
  432. successful WebSocket handshake.
  433. @par Example
  434. Setting the write buffer size.
  435. @code
  436. ws.write_buffer_bytes(8192);
  437. @endcode
  438. @param amount The size of the write buffer in bytes.
  439. */
  440. void
  441. write_buffer_bytes(std::size_t amount);
  442. /// Returns the size of the write buffer.
  443. std::size_t
  444. write_buffer_bytes() const;
  445. /** Set the text message write option.
  446. This controls whether or not outgoing message opcodes
  447. are set to binary or text. The setting is only applied
  448. at the start when a caller begins a new message. Changing
  449. the opcode after a message is started will only take effect
  450. after the current message being sent is complete.
  451. The default setting is to send text messages.
  452. @param value `true` if outgoing messages should indicate
  453. text, or `false` if they should indicate binary.
  454. @par Example
  455. Setting the message type to text.
  456. @code
  457. ws.text(true);
  458. @endcode
  459. */
  460. void
  461. text(bool value);
  462. /// Returns `true` if the text message write option is set.
  463. bool
  464. text() const;
  465. /*
  466. timer settings
  467. * Timer is disabled
  468. * Close on timeout
  469. - no complete frame received, OR
  470. - no complete frame sent
  471. * Ping on timeout
  472. - ping on no complete frame received
  473. * if can't ping?
  474. */
  475. //--------------------------------------------------------------------------
  476. //
  477. // Handshaking (Client)
  478. //
  479. //--------------------------------------------------------------------------
  480. /** Perform the WebSocket handshake in the client role.
  481. This function is used to perform the
  482. <a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
  483. required before messages can be sent and received. During the handshake,
  484. the client sends the Websocket Upgrade HTTP request, and the server
  485. replies with an HTTP response indicating the result of the handshake.
  486. The call blocks until one of the following conditions is true:
  487. @li The request is sent and the response is received.
  488. @li An error occurs.
  489. The algorithm, known as a <em>composed operation</em>, is implemented
  490. in terms of calls to the next layer's `read_some` and `write_some`
  491. functions.
  492. The handshake is successful if the received HTTP response
  493. indicates the upgrade was accepted by the server, represented by a
  494. <a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
  495. of @ref beast::http::status::switching_protocols.
  496. @param host The name of the remote host. This is required by
  497. the HTTP protocol to set the "Host" header field.
  498. @param target The request-target, in origin-form. The server may use the
  499. target to distinguish different services on the same listening port.
  500. @throws system_error Thrown on failure.
  501. @par Example
  502. @code
  503. ws.handshake("localhost", "/");
  504. @endcode
  505. @see
  506. @li <a href="https://tools.ietf.org/html/rfc6455#section-4.1">Websocket Opening Handshake Client Requirements (RFC6455)</a>
  507. @li <a href="https://tools.ietf.org/html/rfc7230#section-5.4">Host field (RFC7230)</a>
  508. @li <a href="https://tools.ietf.org/html/rfc7230#section-3.1.1">request-target (RFC7230)</a>
  509. @li <a href="https://tools.ietf.org/html/rfc7230#section-5.3.1">origin-form (RFC7230)</a>
  510. */
  511. void
  512. handshake(
  513. string_view host,
  514. string_view target);
  515. /** Perform the WebSocket handshake in the client role.
  516. This function is used to perform the
  517. <a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
  518. required before messages can be sent and received. During the handshake,
  519. the client sends the Websocket Upgrade HTTP request, and the server
  520. replies with an HTTP response indicating the result of the handshake.
  521. The call blocks until one of the following conditions is true:
  522. @li The request is sent and the response is received.
  523. @li An error occurs.
  524. The algorithm, known as a <em>composed operation</em>, is implemented
  525. in terms of calls to the next layer's `read_some` and `write_some`
  526. functions.
  527. The handshake is successful if the received HTTP response
  528. indicates the upgrade was accepted by the server, represented by a
  529. <a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
  530. of @ref beast::http::status::switching_protocols.
  531. @param res The HTTP Upgrade response returned by the remote
  532. endpoint. The caller may use the response to access any
  533. additional information sent by the server.
  534. @param host The name of the remote host. This is required by
  535. the HTTP protocol to set the "Host" header field.
  536. @param target The request-target, in origin-form. The server may use the
  537. target to distinguish different services on the same listening port.
  538. @throws system_error Thrown on failure.
  539. @par Example
  540. @code
  541. response_type res;
  542. ws.handshake(res, "localhost", "/");
  543. std::cout << res;
  544. @endcode
  545. @see
  546. @li <a href="https://tools.ietf.org/html/rfc6455#section-4.1">Websocket Opening Handshake Client Requirements (RFC6455)</a>
  547. @li <a href="https://tools.ietf.org/html/rfc7230#section-5.4">Host field (RFC7230)</a>
  548. @li <a href="https://tools.ietf.org/html/rfc7230#section-3.1.1">request-target (RFC7230)</a>
  549. @li <a href="https://tools.ietf.org/html/rfc7230#section-5.3.1">origin-form (RFC7230)</a>
  550. */
  551. void
  552. handshake(
  553. response_type& res,
  554. string_view host,
  555. string_view target);
  556. /** Perform the WebSocket handshake in the client role.
  557. This function is used to perform the
  558. <a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
  559. required before messages can be sent and received. During the handshake,
  560. the client sends the Websocket Upgrade HTTP request, and the server
  561. replies with an HTTP response indicating the result of the handshake.
  562. The call blocks until one of the following conditions is true:
  563. @li The request is sent and the response is received.
  564. @li An error occurs.
  565. The algorithm, known as a <em>composed operation</em>, is implemented
  566. in terms of calls to the next layer's `read_some` and `write_some`
  567. functions.
  568. The handshake is successful if the received HTTP response
  569. indicates the upgrade was accepted by the server, represented by a
  570. <a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
  571. of @ref beast::http::status::switching_protocols.
  572. @param host The name of the remote host. This is required by
  573. the HTTP protocol to set the "Host" header field.
  574. @param target The request-target, in origin-form. The server may use the
  575. target to distinguish different services on the same listening port.
  576. @param ec Set to indicate what error occurred, if any.
  577. @par Example
  578. @code
  579. error_code ec;
  580. ws.handshake("localhost", "/", ec);
  581. @endcode
  582. @see
  583. @li <a href="https://tools.ietf.org/html/rfc6455#section-4.1">Websocket Opening Handshake Client Requirements (RFC6455)</a>
  584. @li <a href="https://tools.ietf.org/html/rfc7230#section-5.4">Host field (RFC7230)</a>
  585. @li <a href="https://tools.ietf.org/html/rfc7230#section-3.1.1">request-target (RFC7230)</a>
  586. @li <a href="https://tools.ietf.org/html/rfc7230#section-5.3.1">origin-form (RFC7230)</a>
  587. */
  588. void
  589. handshake(
  590. string_view host,
  591. string_view target,
  592. error_code& ec);
  593. /** Perform the WebSocket handshake in the client role.
  594. This function is used to perform the
  595. <a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
  596. required before messages can be sent and received. During the handshake,
  597. the client sends the Websocket Upgrade HTTP request, and the server
  598. replies with an HTTP response indicating the result of the handshake.
  599. The call blocks until one of the following conditions is true:
  600. @li The request is sent and the response is received.
  601. @li An error occurs.
  602. The algorithm, known as a <em>composed operation</em>, is implemented
  603. in terms of calls to the next layer's `read_some` and `write_some`
  604. functions.
  605. The handshake is successful if the received HTTP response
  606. indicates the upgrade was accepted by the server, represented by a
  607. <a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
  608. of @ref beast::http::status::switching_protocols.
  609. @param res The HTTP Upgrade response returned by the remote
  610. endpoint. The caller may use the response to access any
  611. additional information sent by the server.
  612. @param host The name of the remote host. This is required by
  613. the HTTP protocol to set the "Host" header field.
  614. @param target The request-target, in origin-form. The server may use the
  615. target to distinguish different services on the same listening port.
  616. @param ec Set to indicate what error occurred, if any.
  617. @par Example
  618. @code
  619. error_code ec;
  620. response_type res;
  621. ws.handshake(res, "localhost", "/", ec);
  622. if(! ec)
  623. std::cout << res;
  624. @endcode
  625. @see
  626. @li <a href="https://tools.ietf.org/html/rfc6455#section-4.1">Websocket Opening Handshake Client Requirements (RFC6455)</a>
  627. @li <a href="https://tools.ietf.org/html/rfc7230#section-5.4">Host field (RFC7230)</a>
  628. @li <a href="https://tools.ietf.org/html/rfc7230#section-3.1.1">request-target (RFC7230)</a>
  629. @li <a href="https://tools.ietf.org/html/rfc7230#section-5.3.1">origin-form (RFC7230)</a>
  630. */
  631. void
  632. handshake(
  633. response_type& res,
  634. string_view host,
  635. string_view target,
  636. error_code& ec);
  637. /** Perform the WebSocket handshake asynchronously in the client role.
  638. This initiating function is used to asynchronously begin performing the
  639. <a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
  640. required before messages can be sent and received. During the handshake,
  641. the client sends the Websocket Upgrade HTTP request, and the server
  642. replies with an HTTP response indicating the result of the handshake.
  643. This call always returns immediately. The asynchronous operation
  644. will continue until one of the following conditions is true:
  645. @li The request is sent and the response is received.
  646. @li An error occurs.
  647. The algorithm, known as a <em>composed asynchronous operation</em>,
  648. is implemented in terms of calls to the next layer's `async_read_some`
  649. and `async_write_some` functions. No other operation may be performed
  650. on the stream until this operation completes.
  651. The handshake is successful if the received HTTP response
  652. indicates the upgrade was accepted by the server, represented by a
  653. <a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
  654. of @ref beast::http::status::switching_protocols.
  655. @param host The name of the remote host. This is required by
  656. the HTTP protocol to set the "Host" header field.
  657. The implementation will not access the string data after the
  658. initiating function returns.
  659. @param target The request-target, in origin-form. The server may use the
  660. target to distinguish different services on the same listening port.
  661. The implementation will not access the string data after the
  662. initiating function returns.
  663. @param handler The completion handler to invoke when the operation
  664. completes. The implementation takes ownership of the handler by
  665. performing a decay-copy. The equivalent function signature of
  666. the handler must be:
  667. @code
  668. void handler(
  669. error_code const& ec // Result of operation
  670. );
  671. @endcode
  672. Regardless of whether the asynchronous operation completes
  673. immediately or not, the handler will not be invoked from within
  674. this function. Invocation of the handler will be performed in a
  675. manner equivalent to using `net::post`.
  676. @par Example
  677. @code
  678. ws.async_handshake("localhost", "/",
  679. [](error_code ec)
  680. {
  681. if(ec)
  682. std::cerr << "Error: " << ec.message() << "\n";
  683. });
  684. @endcode
  685. @see
  686. @li <a href="https://tools.ietf.org/html/rfc6455#section-4.1">Websocket Opening Handshake Client Requirements (RFC6455)</a>
  687. @li <a href="https://tools.ietf.org/html/rfc7230#section-5.4">Host field (RFC7230)</a>
  688. @li <a href="https://tools.ietf.org/html/rfc7230#section-3.1.1">request-target (RFC7230)</a>
  689. @li <a href="https://tools.ietf.org/html/rfc7230#section-5.3.1">origin-form (RFC7230)</a>
  690. */
  691. template<
  692. BOOST_BEAST_ASYNC_TPARAM1 HandshakeHandler =
  693. net::default_completion_token_t<executor_type>
  694. >
  695. BOOST_BEAST_ASYNC_RESULT1(HandshakeHandler)
  696. async_handshake(
  697. string_view host,
  698. string_view target,
  699. HandshakeHandler&& handler =
  700. net::default_completion_token_t<
  701. executor_type>{});
  702. /** Perform the WebSocket handshake asynchronously in the client role.
  703. This initiating function is used to asynchronously begin performing the
  704. <a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
  705. required before messages can be sent and received. During the handshake,
  706. the client sends the Websocket Upgrade HTTP request, and the server
  707. replies with an HTTP response indicating the result of the handshake.
  708. This call always returns immediately. The asynchronous operation
  709. will continue until one of the following conditions is true:
  710. @li The request is sent and the response is received.
  711. @li An error occurs.
  712. The algorithm, known as a <em>composed asynchronous operation</em>,
  713. is implemented in terms of calls to the next layer's `async_read_some`
  714. and `async_write_some` functions. No other operation may be performed
  715. on the stream until this operation completes.
  716. The handshake is successful if the received HTTP response
  717. indicates the upgrade was accepted by the server, represented by a
  718. <a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
  719. of @ref beast::http::status::switching_protocols.
  720. @param res The HTTP Upgrade response returned by the remote
  721. endpoint. The caller may use the response to access any
  722. additional information sent by the server. This object will
  723. be assigned before the completion handler is invoked.
  724. @param host The name of the remote host. This is required by
  725. the HTTP protocol to set the "Host" header field.
  726. The implementation will not access the string data after the
  727. initiating function returns.
  728. @param target The request-target, in origin-form. The server may use the
  729. target to distinguish different services on the same listening port.
  730. The implementation will not access the string data after the
  731. initiating function returns.
  732. @param handler The completion handler to invoke when the operation
  733. completes. The implementation takes ownership of the handler by
  734. performing a decay-copy. The equivalent function signature of
  735. the handler must be:
  736. @code
  737. void handler(
  738. error_code const& ec // Result of operation
  739. );
  740. @endcode
  741. Regardless of whether the asynchronous operation completes
  742. immediately or not, the handler will not be invoked from within
  743. this function. Invocation of the handler will be performed in a
  744. manner equivalent to using `net::post`.
  745. @par Example
  746. @code
  747. response_type res;
  748. ws.async_handshake(res, "localhost", "/",
  749. [&res](error_code ec)
  750. {
  751. if(ec)
  752. std::cerr << "Error: " << ec.message() << "\n";
  753. else
  754. std::cout << res;
  755. });
  756. @endcode
  757. @see
  758. @li <a href="https://tools.ietf.org/html/rfc6455#section-4.1">Websocket Opening Handshake Client Requirements (RFC6455)</a>
  759. @li <a href="https://tools.ietf.org/html/rfc7230#section-5.4">Host field (RFC7230)</a>
  760. @li <a href="https://tools.ietf.org/html/rfc7230#section-3.1.1">request-target (RFC7230)</a>
  761. @li <a href="https://tools.ietf.org/html/rfc7230#section-5.3.1">origin-form (RFC7230)</a>
  762. */
  763. template<
  764. BOOST_BEAST_ASYNC_TPARAM1 HandshakeHandler =
  765. net::default_completion_token_t<executor_type>
  766. >
  767. BOOST_BEAST_ASYNC_RESULT1(HandshakeHandler)
  768. async_handshake(
  769. response_type& res,
  770. string_view host,
  771. string_view target,
  772. HandshakeHandler&& handler =
  773. net::default_completion_token_t<
  774. executor_type>{});
  775. //--------------------------------------------------------------------------
  776. //
  777. // Handshaking (Server)
  778. //
  779. //--------------------------------------------------------------------------
  780. /** Perform the WebSocket handshake in the server role.
  781. This function is used to perform the
  782. <a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
  783. required before messages can be sent and received. During the handshake,
  784. the client sends the Websocket Upgrade HTTP request, and the server
  785. replies with an HTTP response indicating the result of the handshake.
  786. The call blocks until one of the following conditions is true:
  787. @li The request is received and the response is sent.
  788. @li An error occurs.
  789. The algorithm, known as a <em>composed operation</em>, is implemented
  790. in terms of calls to the next layer's `read_some` and `write_some`
  791. functions.
  792. If a valid upgrade request is received, an HTTP response with a
  793. <a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
  794. of @ref beast::http::status::switching_protocols is sent to
  795. the peer, otherwise a non-successful error is associated with
  796. the operation.
  797. If the request size exceeds the capacity of the stream's
  798. internal buffer, the error @ref error::buffer_overflow will be
  799. indicated. To handle larger requests, an application should
  800. read the HTTP request directly using @ref http::read and then
  801. pass the request to the appropriate overload of @ref accept or
  802. @ref async_accept
  803. @throws system_error Thrown on failure.
  804. @see
  805. @li <a href="https://tools.ietf.org/html/rfc6455#section-4.2">Websocket Opening Handshake Server Requirements (RFC6455)</a>
  806. */
  807. void
  808. accept();
  809. /** Read and respond to a WebSocket HTTP Upgrade request.
  810. This function is used to perform the
  811. <a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
  812. required before messages can be sent and received. During the handshake,
  813. the client sends the Websocket Upgrade HTTP request, and the server
  814. replies with an HTTP response indicating the result of the handshake.
  815. The call blocks until one of the following conditions is true:
  816. @li The request is received and the response is sent.
  817. @li An error occurs.
  818. The algorithm, known as a <em>composed operation</em>, is implemented
  819. in terms of calls to the next layer's `read_some` and `write_some`
  820. functions.
  821. If a valid upgrade request is received, an HTTP response with a
  822. <a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
  823. of @ref beast::http::status::switching_protocols is sent to
  824. the peer, otherwise a non-successful error is associated with
  825. the operation.
  826. If the request size exceeds the capacity of the stream's
  827. internal buffer, the error @ref error::buffer_overflow will be
  828. indicated. To handle larger requests, an application should
  829. read the HTTP request directly using @ref http::read and then
  830. pass the request to the appropriate overload of @ref accept or
  831. @ref async_accept
  832. @param ec Set to indicate what error occurred, if any.
  833. @see
  834. @li <a href="https://tools.ietf.org/html/rfc6455#section-4.2">Websocket Opening Handshake Server Requirements (RFC6455)</a>
  835. */
  836. void
  837. accept(error_code& ec);
  838. /** Read and respond to a WebSocket HTTP Upgrade request.
  839. This function is used to perform the
  840. <a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
  841. required before messages can be sent and received. During the handshake,
  842. the client sends the Websocket Upgrade HTTP request, and the server
  843. replies with an HTTP response indicating the result of the handshake.
  844. The call blocks until one of the following conditions is true:
  845. @li The request is received and the response is sent.
  846. @li An error occurs.
  847. The algorithm, known as a <em>composed operation</em>, is implemented
  848. in terms of calls to the next layer's `read_some` and `write_some`
  849. functions.
  850. If a valid upgrade request is received, an HTTP response with a
  851. <a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
  852. of @ref beast::http::status::switching_protocols is sent to
  853. the peer, otherwise a non-successful error is associated with
  854. the operation.
  855. If the request size exceeds the capacity of the stream's
  856. internal buffer, the error @ref error::buffer_overflow will be
  857. indicated. To handle larger requests, an application should
  858. read the HTTP request directly using @ref http::read and then
  859. pass the request to the appropriate overload of @ref accept or
  860. @ref async_accept
  861. @param buffers Caller provided data that has already been
  862. received on the stream. The implementation will copy the
  863. caller provided data before the function returns.
  864. @throws system_error Thrown on failure.
  865. @see
  866. @li <a href="https://tools.ietf.org/html/rfc6455#section-4.2">Websocket Opening Handshake Server Requirements (RFC6455)</a>
  867. */
  868. template<class ConstBufferSequence>
  869. #if BOOST_BEAST_DOXYGEN
  870. void
  871. #else
  872. typename std::enable_if<! http::detail::is_header<
  873. ConstBufferSequence>::value>::type
  874. #endif
  875. accept(ConstBufferSequence const& buffers);
  876. /** Read and respond to a WebSocket HTTP Upgrade request.
  877. This function is used to perform the
  878. <a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
  879. required before messages can be sent and received. During the handshake,
  880. the client sends the Websocket Upgrade HTTP request, and the server
  881. replies with an HTTP response indicating the result of the handshake.
  882. The call blocks until one of the following conditions is true:
  883. @li The request is received and the response is sent.
  884. @li An error occurs.
  885. The algorithm, known as a <em>composed operation</em>, is implemented
  886. in terms of calls to the next layer's `read_some` and `write_some`
  887. functions.
  888. If a valid upgrade request is received, an HTTP response with a
  889. <a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
  890. of @ref beast::http::status::switching_protocols is sent to
  891. the peer, otherwise a non-successful error is associated with
  892. the operation.
  893. If the request size exceeds the capacity of the stream's
  894. internal buffer, the error @ref error::buffer_overflow will be
  895. indicated. To handle larger requests, an application should
  896. read the HTTP request directly using @ref http::read and then
  897. pass the request to the appropriate overload of @ref accept or
  898. @ref async_accept
  899. @param buffers Caller provided data that has already been
  900. received on the stream. The implementation will copy the
  901. caller provided data before the function returns.
  902. @param ec Set to indicate what error occurred, if any.
  903. @see
  904. @li <a href="https://tools.ietf.org/html/rfc6455#section-4.2">Websocket Opening Handshake Server Requirements (RFC6455)</a>
  905. */
  906. template<class ConstBufferSequence>
  907. #if BOOST_BEAST_DOXYGEN
  908. void
  909. #else
  910. typename std::enable_if<! http::detail::is_header<
  911. ConstBufferSequence>::value>::type
  912. #endif
  913. accept(
  914. ConstBufferSequence const& buffers,
  915. error_code& ec);
  916. /** Respond to a WebSocket HTTP Upgrade request
  917. This function is used to perform the
  918. <a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
  919. required before messages can be sent and received. During the handshake,
  920. the client sends the Websocket Upgrade HTTP request, and the server
  921. replies with an HTTP response indicating the result of the handshake.
  922. The call blocks until one of the following conditions is true:
  923. @li The response is sent.
  924. @li An error occurs.
  925. The algorithm, known as a <em>composed operation</em>, is implemented
  926. in terms of calls to the next layer's `read_some` and `write_some`
  927. functions.
  928. If a valid upgrade request is received, an HTTP response with a
  929. <a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
  930. of @ref beast::http::status::switching_protocols is sent to
  931. the peer, otherwise a non-successful error is associated with
  932. the operation.
  933. @param req An object containing the HTTP Upgrade request.
  934. Ownership is not transferred, the implementation will not
  935. access this object from other threads.
  936. @throws system_error Thrown on failure.
  937. @see
  938. @li <a href="https://tools.ietf.org/html/rfc6455#section-4.2">Websocket Opening Handshake Server Requirements (RFC6455)</a>
  939. */
  940. template<class Body, class Allocator>
  941. void
  942. accept(http::request<Body,
  943. http::basic_fields<Allocator>> const& req);
  944. /** Respond to a WebSocket HTTP Upgrade request
  945. This function is used to perform the
  946. <a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
  947. required before messages can be sent and received. During the handshake,
  948. the client sends the Websocket Upgrade HTTP request, and the server
  949. replies with an HTTP response indicating the result of the handshake.
  950. The call blocks until one of the following conditions is true:
  951. @li The response is sent.
  952. @li An error occurs.
  953. The algorithm, known as a <em>composed operation</em>, is implemented
  954. in terms of calls to the next layer's `read_some` and `write_some`
  955. functions.
  956. If a valid upgrade request is received, an HTTP response with a
  957. <a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
  958. of @ref beast::http::status::switching_protocols is sent to
  959. the peer, otherwise a non-successful error is associated with
  960. the operation.
  961. @param req An object containing the HTTP Upgrade request.
  962. Ownership is not transferred, the implementation will not
  963. access this object from other threads.
  964. @param ec Set to indicate what error occurred, if any.
  965. @see
  966. @li <a href="https://tools.ietf.org/html/rfc6455#section-4.2">Websocket Opening Handshake Server Requirements (RFC6455)</a>
  967. */
  968. template<class Body, class Allocator>
  969. void
  970. accept(http::request<Body,
  971. http::basic_fields<Allocator>> const& req,
  972. error_code& ec);
  973. /** Perform the WebSocket handshake asynchronously in the server role.
  974. This initiating function is used to asynchronously begin performing the
  975. <a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
  976. required before messages can be sent and received. During the handshake,
  977. the client sends the Websocket Upgrade HTTP request, and the server
  978. replies with an HTTP response indicating the result of the handshake.
  979. This call always returns immediately. The asynchronous operation
  980. will continue until one of the following conditions is true:
  981. @li The request is received and the response is sent.
  982. @li An error occurs.
  983. The algorithm, known as a <em>composed asynchronous operation</em>,
  984. is implemented in terms of calls to the next layer's `async_read_some`
  985. and `async_write_some` functions. No other operation may be performed
  986. on the stream until this operation completes.
  987. If a valid upgrade request is received, an HTTP response with a
  988. <a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
  989. of @ref beast::http::status::switching_protocols is sent to
  990. the peer, otherwise a non-successful error is associated with
  991. the operation.
  992. If the request size exceeds the capacity of the stream's
  993. internal buffer, the error @ref error::buffer_overflow will be
  994. indicated. To handle larger requests, an application should
  995. read the HTTP request directly using @ref http::async_read and then
  996. pass the request to the appropriate overload of @ref accept or
  997. @ref async_accept
  998. @param handler The completion handler to invoke when the operation
  999. completes. The implementation takes ownership of the handler by
  1000. performing a decay-copy. The equivalent function signature of
  1001. the handler must be:
  1002. @code
  1003. void handler(
  1004. error_code const& ec // Result of operation
  1005. );
  1006. @endcode
  1007. Regardless of whether the asynchronous operation completes
  1008. immediately or not, the handler will not be invoked from within
  1009. this function. Invocation of the handler will be performed in a
  1010. manner equivalent to using `net::post`.
  1011. @see
  1012. @li <a href="https://tools.ietf.org/html/rfc6455#section-4.2">Websocket Opening Handshake Server Requirements (RFC6455)</a>
  1013. */
  1014. template<
  1015. BOOST_BEAST_ASYNC_TPARAM1 AcceptHandler =
  1016. net::default_completion_token_t<executor_type>
  1017. >
  1018. BOOST_BEAST_ASYNC_RESULT1(AcceptHandler)
  1019. async_accept(
  1020. AcceptHandler&& handler =
  1021. net::default_completion_token_t<
  1022. executor_type>{});
  1023. /** Perform the WebSocket handshake asynchronously in the server role.
  1024. This initiating function is used to asynchronously begin performing the
  1025. <a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
  1026. required before messages can be sent and received. During the handshake,
  1027. the client sends the Websocket Upgrade HTTP request, and the server
  1028. replies with an HTTP response indicating the result of the handshake.
  1029. This call always returns immediately. The asynchronous operation
  1030. will continue until one of the following conditions is true:
  1031. @li The request is received and the response is sent.
  1032. @li An error occurs.
  1033. The algorithm, known as a <em>composed asynchronous operation</em>,
  1034. is implemented in terms of calls to the next layer's `async_read_some`
  1035. and `async_write_some` functions. No other operation may be performed
  1036. on the stream until this operation completes.
  1037. If a valid upgrade request is received, an HTTP response with a
  1038. <a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
  1039. of @ref beast::http::status::switching_protocols is sent to
  1040. the peer, otherwise a non-successful error is associated with
  1041. the operation.
  1042. If the request size exceeds the capacity of the stream's
  1043. internal buffer, the error @ref error::buffer_overflow will be
  1044. indicated. To handle larger requests, an application should
  1045. read the HTTP request directly using @ref http::async_read and then
  1046. pass the request to the appropriate overload of @ref accept or
  1047. @ref async_accept
  1048. @param buffers Caller provided data that has already been
  1049. received on the stream. This may be used for implementations
  1050. allowing multiple protocols on the same stream. The
  1051. buffered data will first be applied to the handshake, and
  1052. then to received WebSocket frames. The implementation will
  1053. copy the caller provided data before the function returns.
  1054. @param handler The completion handler to invoke when the operation
  1055. completes. The implementation takes ownership of the handler by
  1056. performing a decay-copy. The equivalent function signature of
  1057. the handler must be:
  1058. @code
  1059. void handler(
  1060. error_code const& ec // Result of operation
  1061. );
  1062. @endcode
  1063. Regardless of whether the asynchronous operation completes
  1064. immediately or not, the handler will not be invoked from within
  1065. this function. Invocation of the handler will be performed in a
  1066. manner equivalent to using `net::post`.
  1067. @see
  1068. @li <a href="https://tools.ietf.org/html/rfc6455#section-4.2">Websocket Opening Handshake Server Requirements (RFC6455)</a>
  1069. */
  1070. template<
  1071. class ConstBufferSequence,
  1072. BOOST_BEAST_ASYNC_TPARAM1 AcceptHandler =
  1073. net::default_completion_token_t<executor_type>
  1074. >
  1075. BOOST_BEAST_ASYNC_RESULT1(AcceptHandler)
  1076. async_accept(
  1077. ConstBufferSequence const& buffers,
  1078. AcceptHandler&& handler =
  1079. net::default_completion_token_t<
  1080. executor_type>{}
  1081. #ifndef BOOST_BEAST_DOXYGEN
  1082. , typename std::enable_if<
  1083. ! http::detail::is_header<
  1084. ConstBufferSequence>::value>::type* = 0
  1085. #endif
  1086. );
  1087. /** Perform the WebSocket handshake asynchronously in the server role.
  1088. This initiating function is used to asynchronously begin performing the
  1089. <a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
  1090. required before messages can be sent and received. During the handshake,
  1091. the client sends the Websocket Upgrade HTTP request, and the server
  1092. replies with an HTTP response indicating the result of the handshake.
  1093. This call always returns immediately. The asynchronous operation
  1094. will continue until one of the following conditions is true:
  1095. @li The request is received and the response is sent.
  1096. @li An error occurs.
  1097. The algorithm, known as a <em>composed asynchronous operation</em>,
  1098. is implemented in terms of calls to the next layer's `async_read_some`
  1099. and `async_write_some` functions. No other operation may be performed
  1100. on the stream until this operation completes.
  1101. If a valid upgrade request is received, an HTTP response with a
  1102. <a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
  1103. of @ref beast::http::status::switching_protocols is sent to
  1104. the peer, otherwise a non-successful error is associated with
  1105. the operation.
  1106. @param req An object containing the HTTP Upgrade request.
  1107. Ownership is not transferred, the implementation will not access
  1108. this object from other threads.
  1109. @param handler The completion handler to invoke when the operation
  1110. completes. The implementation takes ownership of the handler by
  1111. performing a decay-copy. The equivalent function signature of
  1112. the handler must be:
  1113. @code
  1114. void handler(
  1115. error_code const& ec // Result of operation
  1116. );
  1117. @endcode
  1118. Regardless of whether the asynchronous operation completes
  1119. immediately or not, the handler will not be invoked from within
  1120. this function. Invocation of the handler will be performed in a
  1121. manner equivalent to using `net::post`.
  1122. @see
  1123. @li <a href="https://tools.ietf.org/html/rfc6455#section-4.2">Websocket Opening Handshake Server Requirements (RFC6455)</a>
  1124. */
  1125. template<
  1126. class Body, class Allocator,
  1127. BOOST_BEAST_ASYNC_TPARAM1 AcceptHandler =
  1128. net::default_completion_token_t<executor_type>
  1129. >
  1130. BOOST_BEAST_ASYNC_RESULT1(AcceptHandler)
  1131. async_accept(
  1132. http::request<Body,
  1133. http::basic_fields<Allocator>> const& req,
  1134. AcceptHandler&& handler =
  1135. net::default_completion_token_t<
  1136. executor_type>{});
  1137. //--------------------------------------------------------------------------
  1138. //
  1139. // Close Frames
  1140. //
  1141. //--------------------------------------------------------------------------
  1142. /** Send a websocket close control frame.
  1143. This function is used to send a
  1144. <a href="https://tools.ietf.org/html/rfc6455#section-5.5.1">close frame</a>,
  1145. which begins the websocket closing handshake. The session ends when
  1146. both ends of the connection have sent and received a close frame.
  1147. The call blocks until one of the following conditions is true:
  1148. @li The close frame is written.
  1149. @li An error occurs.
  1150. The algorithm, known as a <em>composed operation</em>, is implemented
  1151. in terms of calls to the next layer's `write_some` function.
  1152. After beginning the closing handshake, the program should not write
  1153. further message data, pings, or pongs. Instead, the program should
  1154. continue reading message data until an error occurs. A read returning
  1155. @ref error::closed indicates a successful connection closure.
  1156. @param cr The reason for the close.
  1157. If the close reason specifies a close code other than
  1158. @ref beast::websocket::close_code::none, the close frame is
  1159. sent with the close code and optional reason string. Otherwise,
  1160. the close frame is sent with no payload.
  1161. @throws system_error Thrown on failure.
  1162. @see
  1163. @li <a href="https://tools.ietf.org/html/rfc6455#section-7.1.2">Websocket Closing Handshake (RFC6455)</a>
  1164. */
  1165. void
  1166. close(close_reason const& cr);
  1167. /** Send a websocket close control frame.
  1168. This function is used to send a
  1169. <a href="https://tools.ietf.org/html/rfc6455#section-5.5.1">close frame</a>,
  1170. which begins the websocket closing handshake. The session ends when
  1171. both ends of the connection have sent and received a close frame.
  1172. The call blocks until one of the following conditions is true:
  1173. @li The close frame is written.
  1174. @li An error occurs.
  1175. The algorithm, known as a <em>composed operation</em>, is implemented
  1176. in terms of calls to the next layer's `write_some` function.
  1177. After beginning the closing handshake, the program should not write
  1178. further message data, pings, or pongs. Instead, the program should
  1179. continue reading message data until an error occurs. A read returning
  1180. @ref error::closed indicates a successful connection closure.
  1181. @param cr The reason for the close.
  1182. If the close reason specifies a close code other than
  1183. @ref beast::websocket::close_code::none, the close frame is
  1184. sent with the close code and optional reason string. Otherwise,
  1185. the close frame is sent with no payload.
  1186. @param ec Set to indicate what error occurred, if any.
  1187. @see
  1188. @li <a href="https://tools.ietf.org/html/rfc6455#section-7.1.2">Websocket Closing Handshake (RFC6455)</a>
  1189. */
  1190. void
  1191. close(close_reason const& cr, error_code& ec);
  1192. /** Send a websocket close control frame asynchronously.
  1193. This function is used to asynchronously send a
  1194. <a href="https://tools.ietf.org/html/rfc6455#section-5.5.1">close frame</a>,
  1195. which begins the websocket closing handshake. The session ends when
  1196. both ends of the connection have sent and received a close frame.
  1197. This call always returns immediately. The asynchronous operation
  1198. will continue until one of the following conditions is true:
  1199. @li The close frame finishes sending.
  1200. @li An error occurs.
  1201. The algorithm, known as a <em>composed asynchronous operation</em>,
  1202. is implemented in terms of calls to the next layer's `async_write_some`
  1203. function. No other operations except for message reading operations
  1204. should be initiated on the stream after a close operation is started.
  1205. After beginning the closing handshake, the program should not write
  1206. further message data, pings, or pongs. Instead, the program should
  1207. continue reading message data until an error occurs. A read returning
  1208. @ref error::closed indicates a successful connection closure.
  1209. @param cr The reason for the close.
  1210. If the close reason specifies a close code other than
  1211. @ref beast::websocket::close_code::none, the close frame is
  1212. sent with the close code and optional reason string. Otherwise,
  1213. the close frame is sent with no payload.
  1214. @param handler The completion handler to invoke when the operation
  1215. completes. The implementation takes ownership of the handler by
  1216. performing a decay-copy. The equivalent function signature of
  1217. the handler must be:
  1218. @code
  1219. void handler(
  1220. error_code const& ec // Result of operation
  1221. );
  1222. @endcode
  1223. Regardless of whether the asynchronous operation completes
  1224. immediately or not, the handler will not be invoked from within
  1225. this function. Invocation of the handler will be performed in a
  1226. manner equivalent to using `net::post`.
  1227. @see
  1228. @li <a href="https://tools.ietf.org/html/rfc6455#section-7.1.2">Websocket Closing Handshake (RFC6455)</a>
  1229. */
  1230. template<
  1231. BOOST_BEAST_ASYNC_TPARAM1 CloseHandler =
  1232. net::default_completion_token_t<executor_type>
  1233. >
  1234. BOOST_BEAST_ASYNC_RESULT1(CloseHandler)
  1235. async_close(
  1236. close_reason const& cr,
  1237. CloseHandler&& handler =
  1238. net::default_completion_token_t<
  1239. executor_type>{});
  1240. //--------------------------------------------------------------------------
  1241. //
  1242. // Ping/Pong Frames
  1243. //
  1244. //--------------------------------------------------------------------------
  1245. /** Send a websocket ping control frame.
  1246. This function is used to send a
  1247. <a href="https://tools.ietf.org/html/rfc6455#section-5.5.2">ping frame</a>,
  1248. which usually elicits an automatic pong control frame response from
  1249. the peer.
  1250. The call blocks until one of the following conditions is true:
  1251. @li The ping frame is written.
  1252. @li An error occurs.
  1253. The algorithm, known as a <em>composed operation</em>, is implemented
  1254. in terms of calls to the next layer's `write_some` function.
  1255. @param payload The payload of the ping message, which may be empty.
  1256. @throws system_error Thrown on failure.
  1257. */
  1258. void
  1259. ping(ping_data const& payload);
  1260. /** Send a websocket ping control frame.
  1261. This function is used to send a
  1262. <a href="https://tools.ietf.org/html/rfc6455#section-5.5.2">ping frame</a>,
  1263. which usually elicits an automatic pong control frame response from
  1264. the peer.
  1265. The call blocks until one of the following conditions is true:
  1266. @li The ping frame is written.
  1267. @li An error occurs.
  1268. The algorithm, known as a <em>composed operation</em>, is implemented
  1269. in terms of calls to the next layer's `write_some` function.
  1270. @param payload The payload of the ping message, which may be empty.
  1271. @param ec Set to indicate what error occurred, if any.
  1272. */
  1273. void
  1274. ping(ping_data const& payload, error_code& ec);
  1275. /** Send a websocket ping control frame asynchronously.
  1276. This function is used to asynchronously send a
  1277. <a href="https://tools.ietf.org/html/rfc6455#section-5.5.2">ping frame</a>,
  1278. which usually elicits an automatic pong control frame response from
  1279. the peer.
  1280. @li The ping frame is written.
  1281. @li An error occurs.
  1282. The algorithm, known as a <em>composed asynchronous operation</em>,
  1283. is implemented in terms of calls to the next layer's `async_write_some`
  1284. function. The program must ensure that no other calls to @ref ping,
  1285. @ref pong, @ref async_ping, or @ref async_pong are performed until
  1286. this operation completes.
  1287. If a close frame is sent or received before the ping frame is
  1288. sent, the error received by this completion handler will be
  1289. `net::error::operation_aborted`.
  1290. @param payload The payload of the ping message, which may be empty.
  1291. The implementation will not access the contents of this object after
  1292. the initiating function returns.
  1293. @param handler The completion handler to invoke when the operation
  1294. completes. The implementation takes ownership of the handler by
  1295. performing a decay-copy. The equivalent function signature of
  1296. the handler must be:
  1297. @code
  1298. void handler(
  1299. error_code const& ec // Result of operation
  1300. );
  1301. @endcode
  1302. Regardless of whether the asynchronous operation completes
  1303. immediately or not, the handler will not be invoked from within
  1304. this function. Invocation of the handler will be performed in a
  1305. manner equivalent to using `net::post`.
  1306. */
  1307. template<
  1308. BOOST_BEAST_ASYNC_TPARAM1 WriteHandler =
  1309. net::default_completion_token_t<executor_type>
  1310. >
  1311. BOOST_BEAST_ASYNC_RESULT1(WriteHandler)
  1312. async_ping(
  1313. ping_data const& payload,
  1314. WriteHandler&& handler =
  1315. net::default_completion_token_t<
  1316. executor_type>{});
  1317. /** Send a websocket pong control frame.
  1318. This function is used to send a
  1319. <a href="https://tools.ietf.org/html/rfc6455#section-5.5.3">pong frame</a>,
  1320. which is usually sent automatically in response to a ping frame
  1321. from the remote peer.
  1322. The call blocks until one of the following conditions is true:
  1323. @li The pong frame is written.
  1324. @li An error occurs.
  1325. The algorithm, known as a <em>composed operation</em>, is implemented
  1326. in terms of calls to the next layer's `write_some` function.
  1327. WebSocket allows pong frames to be sent at any time, without first
  1328. receiving a ping. An unsolicited pong sent in this fashion may
  1329. indicate to the remote peer that the connection is still active.
  1330. @param payload The payload of the pong message, which may be empty.
  1331. @throws system_error Thrown on failure.
  1332. */
  1333. void
  1334. pong(ping_data const& payload);
  1335. /** Send a websocket pong control frame.
  1336. This function is used to send a
  1337. <a href="https://tools.ietf.org/html/rfc6455#section-5.5.3">pong frame</a>,
  1338. which is usually sent automatically in response to a ping frame
  1339. from the remote peer.
  1340. The call blocks until one of the following conditions is true:
  1341. @li The pong frame is written.
  1342. @li An error occurs.
  1343. The algorithm, known as a <em>composed operation</em>, is implemented
  1344. in terms of calls to the next layer's `write_some` function.
  1345. WebSocket allows pong frames to be sent at any time, without first
  1346. receiving a ping. An unsolicited pong sent in this fashion may
  1347. indicate to the remote peer that the connection is still active.
  1348. @param payload The payload of the pong message, which may be empty.
  1349. @param ec Set to indicate what error occurred, if any.
  1350. */
  1351. void
  1352. pong(ping_data const& payload, error_code& ec);
  1353. /** Send a websocket pong control frame asynchronously.
  1354. This function is used to asynchronously send a
  1355. <a href="https://tools.ietf.org/html/rfc6455#section-5.5.3">pong frame</a>,
  1356. which is usually sent automatically in response to a ping frame
  1357. from the remote peer.
  1358. @li The pong frame is written.
  1359. @li An error occurs.
  1360. The algorithm, known as a <em>composed asynchronous operation</em>,
  1361. is implemented in terms of calls to the next layer's `async_write_some`
  1362. function. The program must ensure that no other calls to @ref ping,
  1363. @ref pong, @ref async_ping, or @ref async_pong are performed until
  1364. this operation completes.
  1365. If a close frame is sent or received before the pong frame is
  1366. sent, the error received by this completion handler will be
  1367. `net::error::operation_aborted`.
  1368. WebSocket allows pong frames to be sent at any time, without first
  1369. receiving a ping. An unsolicited pong sent in this fashion may
  1370. indicate to the remote peer that the connection is still active.
  1371. @param payload The payload of the pong message, which may be empty.
  1372. The implementation will not access the contents of this object after
  1373. the initiating function returns.
  1374. @param handler The completion handler to invoke when the operation
  1375. completes. The implementation takes ownership of the handler by
  1376. performing a decay-copy. The equivalent function signature of
  1377. the handler must be:
  1378. @code
  1379. void handler(
  1380. error_code const& ec // Result of operation
  1381. );
  1382. @endcode
  1383. Regardless of whether the asynchronous operation completes
  1384. immediately or not, the handler will not be invoked from within
  1385. this function. Invocation of the handler will be performed in a
  1386. manner equivalent to using `net::post`.
  1387. */
  1388. template<
  1389. BOOST_BEAST_ASYNC_TPARAM1 WriteHandler =
  1390. net::default_completion_token_t<executor_type>
  1391. >
  1392. BOOST_BEAST_ASYNC_RESULT1(WriteHandler)
  1393. async_pong(
  1394. ping_data const& payload,
  1395. WriteHandler&& handler =
  1396. net::default_completion_token_t<
  1397. executor_type>{});
  1398. //--------------------------------------------------------------------------
  1399. //
  1400. // Reading
  1401. //
  1402. //--------------------------------------------------------------------------
  1403. /** Read a complete message.
  1404. This function is used to read a complete message.
  1405. The call blocks until one of the following is true:
  1406. @li A complete message is received.
  1407. @li A close frame is received. In this case the error indicated by
  1408. the function will be @ref error::closed.
  1409. @li An error occurs.
  1410. The algorithm, known as a <em>composed operation</em>, is implemented
  1411. in terms of calls to the next layer's `read_some` and `write_some`
  1412. functions.
  1413. Received message data is appended to the buffer.
  1414. The functions @ref got_binary and @ref got_text may be used
  1415. to query the stream and determine the type of the last received message.
  1416. Until the call returns, the implementation will read incoming control
  1417. frames and handle them automatically as follows:
  1418. @li The @ref control_callback will be invoked for each control frame.
  1419. @li For each received ping frame, a pong frame will be
  1420. automatically sent.
  1421. @li If a close frame is received, the WebSocket closing handshake is
  1422. performed. In this case, when the function returns, the error
  1423. @ref error::closed will be indicated.
  1424. @return The number of message payload bytes appended to the buffer.
  1425. @param buffer A dynamic buffer to append message data to.
  1426. @throws system_error Thrown on failure.
  1427. */
  1428. template<class DynamicBuffer>
  1429. std::size_t
  1430. read(DynamicBuffer& buffer);
  1431. /** Read a complete message.
  1432. This function is used to read a complete message.
  1433. The call blocks until one of the following is true:
  1434. @li A complete message is received.
  1435. @li A close frame is received. In this case the error indicated by
  1436. the function will be @ref error::closed.
  1437. @li An error occurs.
  1438. The algorithm, known as a <em>composed operation</em>, is implemented
  1439. in terms of calls to the next layer's `read_some` and `write_some`
  1440. functions.
  1441. Received message data is appended to the buffer.
  1442. The functions @ref got_binary and @ref got_text may be used
  1443. to query the stream and determine the type of the last received message.
  1444. Until the call returns, the implementation will read incoming control
  1445. frames and handle them automatically as follows:
  1446. @li The @ref control_callback will be invoked for each control frame.
  1447. @li For each received ping frame, a pong frame will be
  1448. automatically sent.
  1449. @li If a close frame is received, the WebSocket closing handshake is
  1450. performed. In this case, when the function returns, the error
  1451. @ref error::closed will be indicated.
  1452. @return The number of message payload bytes appended to the buffer.
  1453. @param buffer A dynamic buffer to append message data to.
  1454. @param ec Set to indicate what error occurred, if any.
  1455. */
  1456. template<class DynamicBuffer>
  1457. std::size_t
  1458. read(DynamicBuffer& buffer, error_code& ec);
  1459. /** Read a complete message asynchronously.
  1460. This function is used to asynchronously read a complete message.
  1461. This call always returns immediately. The asynchronous operation
  1462. will continue until one of the following conditions is true:
  1463. @li A complete message is received.
  1464. @li A close frame is received. In this case the error indicated by
  1465. the function will be @ref error::closed.
  1466. @li An error occurs.
  1467. The algorithm, known as a <em>composed asynchronous operation</em>,
  1468. is implemented in terms of calls to the next layer's `async_read_some`
  1469. and `async_write_some` functions. The program must ensure that no other
  1470. calls to @ref read, @ref read_some, @ref async_read, or @ref async_read_some
  1471. are performed until this operation completes.
  1472. Received message data is appended to the buffer.
  1473. The functions @ref got_binary and @ref got_text may be used
  1474. to query the stream and determine the type of the last received message.
  1475. Until the operation completes, the implementation will read incoming
  1476. control frames and handle them automatically as follows:
  1477. @li The @ref control_callback will be invoked for each control frame.
  1478. @li For each received ping frame, a pong frame will be
  1479. automatically sent.
  1480. @li If a close frame is received, the WebSocket close procedure is
  1481. performed. In this case, when the function returns, the error
  1482. @ref error::closed will be indicated.
  1483. Pong frames and close frames sent by the implementation while the
  1484. read operation is outstanding do not prevent the application from
  1485. also writing message data, sending pings, sending pongs, or sending
  1486. close frames.
  1487. @param buffer A dynamic buffer to append message data to.
  1488. @param handler The completion handler to invoke when the operation
  1489. completes. The implementation takes ownership of the handler by
  1490. performing a decay-copy. The equivalent function signature of
  1491. the handler must be:
  1492. @code
  1493. void handler(
  1494. error_code const& ec, // Result of operation
  1495. std::size_t bytes_written // Number of bytes appended to buffer
  1496. );
  1497. @endcode
  1498. Regardless of whether the asynchronous operation completes
  1499. immediately or not, the handler will not be invoked from within
  1500. this function. Invocation of the handler will be performed in a
  1501. manner equivalent to using `net::post`.
  1502. */
  1503. template<
  1504. class DynamicBuffer,
  1505. BOOST_BEAST_ASYNC_TPARAM2 ReadHandler =
  1506. net::default_completion_token_t<
  1507. executor_type>>
  1508. BOOST_BEAST_ASYNC_RESULT2(ReadHandler)
  1509. async_read(
  1510. DynamicBuffer& buffer,
  1511. ReadHandler&& handler =
  1512. net::default_completion_token_t<
  1513. executor_type>{});
  1514. //--------------------------------------------------------------------------
  1515. /** Read some message data.
  1516. This function is used to read some message data.
  1517. The call blocks until one of the following is true:
  1518. @li Some message data is received.
  1519. @li A close frame is received. In this case the error indicated by
  1520. the function will be @ref error::closed.
  1521. @li An error occurs.
  1522. The algorithm, known as a <em>composed operation</em>, is implemented
  1523. in terms of calls to the next layer's `read_some` and `write_some`
  1524. functions.
  1525. Received message data is appended to the buffer.
  1526. The functions @ref got_binary and @ref got_text may be used
  1527. to query the stream and determine the type of the last received message.
  1528. The function @ref is_message_done may be called to determine if the
  1529. message received by the last read operation is complete.
  1530. Until the call returns, the implementation will read incoming control
  1531. frames and handle them automatically as follows:
  1532. @li The @ref control_callback will be invoked for each control frame.
  1533. @li For each received ping frame, a pong frame will be
  1534. automatically sent.
  1535. @li If a close frame is received, the WebSocket closing handshake is
  1536. performed. In this case, when the function returns, the error
  1537. @ref error::closed will be indicated.
  1538. @return The number of message payload bytes appended to the buffer.
  1539. @param buffer A dynamic buffer to append message data to.
  1540. @param limit An upper limit on the number of bytes this function
  1541. will append into the buffer. If this value is zero, then a reasonable
  1542. size will be chosen automatically.
  1543. @throws system_error Thrown on failure.
  1544. */
  1545. template<class DynamicBuffer>
  1546. std::size_t
  1547. read_some(
  1548. DynamicBuffer& buffer,
  1549. std::size_t limit);
  1550. /** Read some message data.
  1551. This function is used to read some message data.
  1552. The call blocks until one of the following is true:
  1553. @li Some message data is received.
  1554. @li A close frame is received. In this case the error indicated by
  1555. the function will be @ref error::closed.
  1556. @li An error occurs.
  1557. The algorithm, known as a <em>composed operation</em>, is implemented
  1558. in terms of calls to the next layer's `read_some` and `write_some`
  1559. functions.
  1560. Received message data is appended to the buffer.
  1561. The functions @ref got_binary and @ref got_text may be used
  1562. to query the stream and determine the type of the last received message.
  1563. The function @ref is_message_done may be called to determine if the
  1564. message received by the last read operation is complete.
  1565. Until the call returns, the implementation will read incoming control
  1566. frames and handle them automatically as follows:
  1567. @li The @ref control_callback will be invoked for each control frame.
  1568. @li For each received ping frame, a pong frame will be
  1569. automatically sent.
  1570. @li If a close frame is received, the WebSocket closing handshake is
  1571. performed. In this case, when the function returns, the error
  1572. @ref error::closed will be indicated.
  1573. @return The number of message payload bytes appended to the buffer.
  1574. @param buffer A dynamic buffer to append message data to.
  1575. @param limit An upper limit on the number of bytes this function
  1576. will append into the buffer. If this value is zero, then a reasonable
  1577. size will be chosen automatically.
  1578. @param ec Set to indicate what error occurred, if any.
  1579. */
  1580. template<class DynamicBuffer>
  1581. std::size_t
  1582. read_some(
  1583. DynamicBuffer& buffer,
  1584. std::size_t limit,
  1585. error_code& ec);
  1586. /** Read some message data asynchronously.
  1587. This function is used to asynchronously read some message data.
  1588. This call always returns immediately. The asynchronous operation
  1589. will continue until one of the following conditions is true:
  1590. @li Some message data is received.
  1591. @li A close frame is received. In this case the error indicated by
  1592. the function will be @ref error::closed.
  1593. @li An error occurs.
  1594. The algorithm, known as a <em>composed asynchronous operation</em>,
  1595. is implemented in terms of calls to the next layer's `async_read_some`
  1596. and `async_write_some` functions. The program must ensure that no other
  1597. calls to @ref read, @ref read_some, @ref async_read, or @ref async_read_some
  1598. are performed until this operation completes.
  1599. Received message data is appended to the buffer.
  1600. The functions @ref got_binary and @ref got_text may be used
  1601. to query the stream and determine the type of the last received message.
  1602. Until the operation completes, the implementation will read incoming
  1603. control frames and handle them automatically as follows:
  1604. @li The @ref control_callback will be invoked for each control frame.
  1605. @li For each received ping frame, a pong frame will be
  1606. automatically sent.
  1607. @li If a close frame is received, the WebSocket close procedure is
  1608. performed. In this case, when the function returns, the error
  1609. @ref error::closed will be indicated.
  1610. Pong frames and close frames sent by the implementation while the
  1611. read operation is outstanding do not prevent the application from
  1612. also writing message data, sending pings, sending pongs, or sending
  1613. close frames.
  1614. @param buffer A dynamic buffer to append message data to.
  1615. @param limit An upper limit on the number of bytes this function
  1616. will append into the buffer. If this value is zero, then a reasonable
  1617. size will be chosen automatically.
  1618. @param handler The completion handler to invoke when the operation
  1619. completes. The implementation takes ownership of the handler by
  1620. performing a decay-copy. The equivalent function signature of
  1621. the handler must be:
  1622. @code
  1623. void handler(
  1624. error_code const& ec, // Result of operation
  1625. std::size_t bytes_written // Number of bytes appended to buffer
  1626. );
  1627. @endcode
  1628. Regardless of whether the asynchronous operation completes
  1629. immediately or not, the handler will not be invoked from within
  1630. this function. Invocation of the handler will be performed in a
  1631. manner equivalent to using `net::post`.
  1632. */
  1633. template<
  1634. class DynamicBuffer,
  1635. BOOST_BEAST_ASYNC_TPARAM2 ReadHandler =
  1636. net::default_completion_token_t<
  1637. executor_type>>
  1638. BOOST_BEAST_ASYNC_RESULT2(ReadHandler)
  1639. async_read_some(
  1640. DynamicBuffer& buffer,
  1641. std::size_t limit,
  1642. ReadHandler&& handler =
  1643. net::default_completion_token_t<
  1644. executor_type>{});
  1645. //--------------------------------------------------------------------------
  1646. /** Read some message data.
  1647. This function is used to read some message data.
  1648. The call blocks until one of the following is true:
  1649. @li Some message data is received.
  1650. @li A close frame is received. In this case the error indicated by
  1651. the function will be @ref error::closed.
  1652. @li An error occurs.
  1653. The algorithm, known as a <em>composed operation</em>, is implemented
  1654. in terms of calls to the next layer's `read_some` and `write_some`
  1655. functions.
  1656. The functions @ref got_binary and @ref got_text may be used
  1657. to query the stream and determine the type of the last received message.
  1658. The function @ref is_message_done may be called to determine if the
  1659. message received by the last read operation is complete.
  1660. Until the call returns, the implementation will read incoming control
  1661. frames and handle them automatically as follows:
  1662. @li The @ref control_callback will be invoked for each control frame.
  1663. @li For each received ping frame, a pong frame will be
  1664. automatically sent.
  1665. @li If a close frame is received, the WebSocket closing handshake is
  1666. performed. In this case, when the function returns, the error
  1667. @ref error::closed will be indicated.
  1668. @return The number of message payload bytes appended to the buffer.
  1669. @param buffers A buffer sequence to write message data into.
  1670. The previous contents of the buffers will be overwritten, starting
  1671. from the beginning.
  1672. @throws system_error Thrown on failure.
  1673. */
  1674. template<class MutableBufferSequence>
  1675. std::size_t
  1676. read_some(
  1677. MutableBufferSequence const& buffers);
  1678. /** Read some message data.
  1679. This function is used to read some message data.
  1680. The call blocks until one of the following is true:
  1681. @li Some message data is received.
  1682. @li A close frame is received. In this case the error indicated by
  1683. the function will be @ref error::closed.
  1684. @li An error occurs.
  1685. The algorithm, known as a <em>composed operation</em>, is implemented
  1686. in terms of calls to the next layer's `read_some` and `write_some`
  1687. functions.
  1688. The functions @ref got_binary and @ref got_text may be used
  1689. to query the stream and determine the type of the last received message.
  1690. The function @ref is_message_done may be called to determine if the
  1691. message received by the last read operation is complete.
  1692. Until the call returns, the implementation will read incoming control
  1693. frames and handle them automatically as follows:
  1694. @li The @ref control_callback will be invoked for each control frame.
  1695. @li For each received ping frame, a pong frame will be
  1696. automatically sent.
  1697. @li If a close frame is received, the WebSocket closing handshake is
  1698. performed. In this case, when the function returns, the error
  1699. @ref error::closed will be indicated.
  1700. @return The number of message payload bytes appended to the buffer.
  1701. @param buffers A buffer sequence to write message data into.
  1702. The previous contents of the buffers will be overwritten, starting
  1703. from the beginning.
  1704. @param ec Set to indicate what error occurred, if any.
  1705. */
  1706. template<class MutableBufferSequence>
  1707. std::size_t
  1708. read_some(
  1709. MutableBufferSequence const& buffers,
  1710. error_code& ec);
  1711. /** Read some message data asynchronously.
  1712. This function is used to asynchronously read some message data.
  1713. This call always returns immediately. The asynchronous operation
  1714. will continue until one of the following conditions is true:
  1715. @li Some message data is received.
  1716. @li A close frame is received. In this case the error indicated by
  1717. the function will be @ref error::closed.
  1718. @li An error occurs.
  1719. The algorithm, known as a <em>composed asynchronous operation</em>,
  1720. is implemented in terms of calls to the next layer's `async_read_some`
  1721. and `async_write_some` functions. The program must ensure that no other
  1722. calls to @ref read, @ref read_some, @ref async_read, or @ref async_read_some
  1723. are performed until this operation completes.
  1724. Received message data is appended to the buffer.
  1725. The functions @ref got_binary and @ref got_text may be used
  1726. to query the stream and determine the type of the last received message.
  1727. Until the operation completes, the implementation will read incoming
  1728. control frames and handle them automatically as follows:
  1729. @li The @ref control_callback will be invoked for each control frame.
  1730. @li For each received ping frame, a pong frame will be
  1731. automatically sent.
  1732. @li If a close frame is received, the WebSocket close procedure is
  1733. performed. In this case, when the function returns, the error
  1734. @ref error::closed will be indicated.
  1735. Pong frames and close frames sent by the implementation while the
  1736. read operation is outstanding do not prevent the application from
  1737. also writing message data, sending pings, sending pongs, or sending
  1738. close frames.
  1739. @param buffers A buffer sequence to write message data into.
  1740. The previous contents of the buffers will be overwritten, starting
  1741. from the beginning.
  1742. The implementation will make copies of this object as needed, but
  1743. but ownership of the underlying memory is not transferred. The
  1744. caller is responsible for ensuring that the memory locations
  1745. pointed to by the buffer sequence remain valid until the
  1746. completion handler is called.
  1747. @param handler The completion handler to invoke when the operation
  1748. completes. The implementation takes ownership of the handler by
  1749. performing a decay-copy. The equivalent function signature of
  1750. the handler must be:
  1751. @code
  1752. void handler(
  1753. error_code const& ec, // Result of operation
  1754. std::size_t bytes_written // Number of bytes written to the buffers
  1755. );
  1756. @endcode
  1757. Regardless of whether the asynchronous operation completes
  1758. immediately or not, the handler will not be invoked from within
  1759. this function. Invocation of the handler will be performed in a
  1760. manner equivalent to using `net::post`.
  1761. */
  1762. template<
  1763. class MutableBufferSequence,
  1764. BOOST_BEAST_ASYNC_TPARAM2 ReadHandler =
  1765. net::default_completion_token_t<
  1766. executor_type>>
  1767. BOOST_BEAST_ASYNC_RESULT2(ReadHandler)
  1768. async_read_some(
  1769. MutableBufferSequence const& buffers,
  1770. ReadHandler&& handler =
  1771. net::default_completion_token_t<
  1772. executor_type>{});
  1773. //--------------------------------------------------------------------------
  1774. //
  1775. // Writing
  1776. //
  1777. //--------------------------------------------------------------------------
  1778. /** Write a complete message.
  1779. This function is used to write a complete message.
  1780. The call blocks until one of the following is true:
  1781. @li The message is written.
  1782. @li An error occurs.
  1783. The algorithm, known as a <em>composed operation</em>, is implemented
  1784. in terms of calls to the next layer's `write_some` function.
  1785. The current setting of the @ref binary option controls
  1786. whether the message opcode is set to text or binary. If the
  1787. @ref auto_fragment option is set, the message will be split
  1788. into one or more frames as necessary. The actual payload contents
  1789. sent may be transformed as per the WebSocket protocol settings.
  1790. @param buffers The buffers containing the message to send.
  1791. @return The number of bytes sent from the buffers.
  1792. @throws system_error Thrown on failure.
  1793. */
  1794. template<class ConstBufferSequence>
  1795. std::size_t
  1796. write(ConstBufferSequence const& buffers);
  1797. /** Write a complete message.
  1798. This function is used to write a complete message.
  1799. The call blocks until one of the following is true:
  1800. @li The complete message is written.
  1801. @li An error occurs.
  1802. The algorithm, known as a <em>composed operation</em>, is implemented
  1803. in terms of calls to the next layer's `write_some` function.
  1804. The current setting of the @ref binary option controls
  1805. whether the message opcode is set to text or binary. If the
  1806. @ref auto_fragment option is set, the message will be split
  1807. into one or more frames as necessary. The actual payload contents
  1808. sent may be transformed as per the WebSocket protocol settings.
  1809. @param buffers The buffers containing the message to send.
  1810. @param ec Set to indicate what error occurred, if any.
  1811. @return The number of bytes sent from the buffers.
  1812. */
  1813. template<class ConstBufferSequence>
  1814. std::size_t
  1815. write(ConstBufferSequence const& buffers, error_code& ec);
  1816. /** Write a complete message asynchronously.
  1817. This function is used to asynchronously write a complete message.
  1818. This call always returns immediately. The asynchronous operation
  1819. will continue until one of the following conditions is true:
  1820. @li The complete message is written.
  1821. @li An error occurs.
  1822. The algorithm, known as a <em>composed asynchronous operation</em>,
  1823. is implemented in terms of calls to the next layer's
  1824. `async_write_some` function. The program must ensure that no other
  1825. calls to @ref write, @ref write_some, @ref async_write, or
  1826. @ref async_write_some are performed until this operation completes.
  1827. The current setting of the @ref binary option controls
  1828. whether the message opcode is set to text or binary. If the
  1829. @ref auto_fragment option is set, the message will be split
  1830. into one or more frames as necessary. The actual payload contents
  1831. sent may be transformed as per the WebSocket protocol settings.
  1832. @param buffers A buffer sequence containing the entire message
  1833. payload. The implementation will make copies of this object
  1834. as needed, but ownership of the underlying memory is not
  1835. transferred. The caller is responsible for ensuring that
  1836. the memory locations pointed to by buffers remains valid
  1837. until the completion handler is called.
  1838. @param handler The completion handler to invoke when the operation
  1839. completes. The implementation takes ownership of the handler by
  1840. performing a decay-copy. The equivalent function signature of
  1841. the handler must be:
  1842. @code
  1843. void handler(
  1844. error_code const& ec, // Result of operation
  1845. std::size_t bytes_transferred // Number of bytes sent from the
  1846. // buffers. If an error occurred,
  1847. // this will be less than the buffer_size.
  1848. );
  1849. @endcode
  1850. Regardless of whether the asynchronous operation completes
  1851. immediately or not, the handler will not be invoked from within
  1852. this function. Invocation of the handler will be performed in a
  1853. manner equivalent to using `net::post`.
  1854. */
  1855. template<
  1856. class ConstBufferSequence,
  1857. BOOST_BEAST_ASYNC_TPARAM2 WriteHandler =
  1858. net::default_completion_token_t<
  1859. executor_type>>
  1860. BOOST_BEAST_ASYNC_RESULT2(WriteHandler)
  1861. async_write(
  1862. ConstBufferSequence const& buffers,
  1863. WriteHandler&& handler =
  1864. net::default_completion_token_t<
  1865. executor_type>{});
  1866. /** Write some message data.
  1867. This function is used to send part of a message.
  1868. The call blocks until one of the following is true:
  1869. @li The message data is written.
  1870. @li An error occurs.
  1871. The algorithm, known as a <em>composed operation</em>, is implemented
  1872. in terms of calls to the next layer's `write_some` function.
  1873. If this is the beginning of a new message, the message opcode
  1874. will be set to text or binary based on the current setting of
  1875. the @ref binary (or @ref text) option. The actual payload sent
  1876. may be transformed as per the WebSocket protocol settings.
  1877. @param fin `true` if this is the last part of the message.
  1878. @param buffers The buffers containing the message part to send.
  1879. @return The number of bytes sent from the buffers.
  1880. @throws system_error Thrown on failure.
  1881. */
  1882. template<class ConstBufferSequence>
  1883. std::size_t
  1884. write_some(bool fin, ConstBufferSequence const& buffers);
  1885. /** Write some message data.
  1886. This function is used to send part of a message.
  1887. The call blocks until one of the following is true:
  1888. @li The message data is written.
  1889. @li An error occurs.
  1890. The algorithm, known as a <em>composed operation</em>, is implemented
  1891. in terms of calls to the next layer's `write_some` function.
  1892. If this is the beginning of a new message, the message opcode
  1893. will be set to text or binary based on the current setting of
  1894. the @ref binary (or @ref text) option. The actual payload sent
  1895. may be transformed as per the WebSocket protocol settings.
  1896. @param fin `true` if this is the last part of the message.
  1897. @param buffers The buffers containing the message part to send.
  1898. @param ec Set to indicate what error occurred, if any.
  1899. @return The number of bytes sent from the buffers.
  1900. @return The number of bytes consumed in the input buffers.
  1901. */
  1902. template<class ConstBufferSequence>
  1903. std::size_t
  1904. write_some(bool fin,
  1905. ConstBufferSequence const& buffers, error_code& ec);
  1906. /** Write some message data asynchronously.
  1907. This function is used to asynchronously write part of a message.
  1908. This call always returns immediately. The asynchronous operation
  1909. will continue until one of the following conditions is true:
  1910. @li The message data is written.
  1911. @li An error occurs.
  1912. The algorithm, known as a <em>composed asynchronous operation</em>,
  1913. is implemented in terms of calls to the next layer's
  1914. `async_write_some` function. The program must ensure that no other
  1915. calls to @ref write, @ref write_some, @ref async_write, or
  1916. @ref async_write_some are performed until this operation completes.
  1917. If this is the beginning of a new message, the message opcode
  1918. will be set to text or binary based on the current setting of
  1919. the @ref binary (or @ref text) option. The actual payload sent
  1920. may be transformed as per the WebSocket protocol settings.
  1921. @param fin `true` if this is the last part of the message.
  1922. @param buffers The buffers containing the message part to send.
  1923. The implementation will make copies of this object
  1924. as needed, but ownership of the underlying memory is not
  1925. transferred. The caller is responsible for ensuring that
  1926. the memory locations pointed to by buffers remains valid
  1927. until the completion handler is called.
  1928. @param handler The completion handler to invoke when the operation
  1929. completes. The implementation takes ownership of the handler by
  1930. performing a decay-copy. The equivalent function signature of
  1931. the handler must be:
  1932. @code
  1933. void handler(
  1934. error_code const& ec, // Result of operation
  1935. std::size_t bytes_transferred // Number of bytes sent from the
  1936. // buffers. If an error occurred,
  1937. // this will be less than the buffer_size.
  1938. );
  1939. @endcode
  1940. Regardless of whether the asynchronous operation completes
  1941. immediately or not, the handler will not be invoked from within
  1942. this function. Invocation of the handler will be performed in a
  1943. manner equivalent to using `net::post`.
  1944. */
  1945. template<
  1946. class ConstBufferSequence,
  1947. BOOST_BEAST_ASYNC_TPARAM2 WriteHandler =
  1948. net::default_completion_token_t<
  1949. executor_type>>
  1950. BOOST_BEAST_ASYNC_RESULT2(WriteHandler)
  1951. async_write_some(
  1952. bool fin,
  1953. ConstBufferSequence const& buffers,
  1954. WriteHandler&& handler =
  1955. net::default_completion_token_t<
  1956. executor_type>{});
  1957. private:
  1958. template<class, class> class accept_op;
  1959. template<class> class close_op;
  1960. template<class> class handshake_op;
  1961. template<class> class ping_op;
  1962. template<class> class idle_ping_op;
  1963. template<class, class> class read_some_op;
  1964. template<class, class> class read_op;
  1965. template<class> class response_op;
  1966. template<class, class> class write_some_op;
  1967. template<class, class> class write_op;
  1968. struct run_accept_op;
  1969. struct run_close_op;
  1970. struct run_handshake_op;
  1971. struct run_ping_op;
  1972. struct run_idle_ping_op;
  1973. struct run_read_some_op;
  1974. struct run_read_op;
  1975. struct run_response_op;
  1976. struct run_write_some_op;
  1977. struct run_write_op;
  1978. static void default_decorate_req(request_type&) {}
  1979. static void default_decorate_res(response_type&) {}
  1980. //
  1981. // accept / handshake
  1982. //
  1983. template<class Buffers, class Decorator>
  1984. void
  1985. do_accept(
  1986. Buffers const& buffers,
  1987. Decorator const& decorator,
  1988. error_code& ec);
  1989. template<
  1990. class Body, class Allocator,
  1991. class Decorator>
  1992. void
  1993. do_accept(
  1994. http::request<Body,
  1995. http::basic_fields<Allocator>> const& req,
  1996. Decorator const& decorator,
  1997. error_code& ec);
  1998. template<class RequestDecorator>
  1999. void
  2000. do_handshake(response_type* res_p,
  2001. string_view host, string_view target,
  2002. RequestDecorator const& decorator,
  2003. error_code& ec);
  2004. //
  2005. // fail
  2006. //
  2007. void
  2008. do_fail(
  2009. std::uint16_t code,
  2010. error_code ev,
  2011. error_code& ec);
  2012. };
  2013. /** Manually provide a one-time seed to initialize the PRNG
  2014. This function invokes the specified seed sequence to produce a seed
  2015. suitable for use with the pseudo-random number generator used to
  2016. create masks and perform WebSocket protocol handshakes.
  2017. If a seed is not manually provided, the implementation will
  2018. perform a one-time seed generation using `std::random_device`. This
  2019. function may be used when the application runs in an environment
  2020. where the random device is unreliable or does not provide sufficient
  2021. entropy.
  2022. @par Preconditions
  2023. This function may not be called after any websocket @ref stream objects
  2024. have been constructed.
  2025. @param ss A reference to a `std::seed_seq` which will be used to seed
  2026. the pseudo-random number generator. The seed sequence should have at
  2027. least 256 bits of entropy.
  2028. @see stream::secure_prng
  2029. */
  2030. inline
  2031. void
  2032. seed_prng(std::seed_seq& ss)
  2033. {
  2034. detail::prng_seed(&ss);
  2035. }
  2036. } // websocket
  2037. } // beast
  2038. } // boost
  2039. #include <boost/beast/websocket/impl/stream_impl.hpp> // must be first
  2040. #include <boost/beast/websocket/impl/accept.hpp>
  2041. #include <boost/beast/websocket/impl/close.hpp>
  2042. #include <boost/beast/websocket/impl/handshake.hpp>
  2043. #include <boost/beast/websocket/impl/ping.hpp>
  2044. #include <boost/beast/websocket/impl/read.hpp>
  2045. #include <boost/beast/websocket/impl/stream.hpp>
  2046. #include <boost/beast/websocket/impl/write.hpp>
  2047. #endif