read.hpp 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287
  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_IMPL_READ_HPP
  10. #define BOOST_BEAST_WEBSOCKET_IMPL_READ_HPP
  11. #include <boost/beast/core/buffer_traits.hpp>
  12. #include <boost/beast/websocket/teardown.hpp>
  13. #include <boost/beast/websocket/detail/mask.hpp>
  14. #include <boost/beast/websocket/impl/stream_impl.hpp>
  15. #include <boost/beast/core/async_base.hpp>
  16. #include <boost/beast/core/bind_handler.hpp>
  17. #include <boost/beast/core/buffers_prefix.hpp>
  18. #include <boost/beast/core/buffers_suffix.hpp>
  19. #include <boost/beast/core/flat_static_buffer.hpp>
  20. #include <boost/beast/core/read_size.hpp>
  21. #include <boost/beast/core/stream_traits.hpp>
  22. #include <boost/beast/core/detail/bind_continuation.hpp>
  23. #include <boost/beast/core/detail/buffer.hpp>
  24. #include <boost/beast/core/detail/clamp.hpp>
  25. #include <boost/beast/core/detail/config.hpp>
  26. #include <boost/asio/coroutine.hpp>
  27. #include <boost/asio/post.hpp>
  28. #include <boost/assert.hpp>
  29. #include <boost/config.hpp>
  30. #include <boost/optional.hpp>
  31. #include <boost/throw_exception.hpp>
  32. #include <algorithm>
  33. #include <limits>
  34. #include <memory>
  35. namespace boost {
  36. namespace beast {
  37. namespace websocket {
  38. /* Read some message data into a buffer sequence.
  39. Also reads and handles control frames.
  40. */
  41. template<class NextLayer, bool deflateSupported>
  42. template<class Handler, class MutableBufferSequence>
  43. class stream<NextLayer, deflateSupported>::read_some_op
  44. : public beast::async_base<
  45. Handler, beast::executor_type<stream>>
  46. , public net::coroutine
  47. {
  48. boost::weak_ptr<impl_type> wp_;
  49. MutableBufferSequence bs_;
  50. buffers_suffix<MutableBufferSequence> cb_;
  51. std::size_t bytes_written_ = 0;
  52. error_code result_;
  53. close_code code_;
  54. bool did_read_ = false;
  55. public:
  56. static constexpr int id = 1; // for soft_mutex
  57. template<class Handler_>
  58. read_some_op(
  59. Handler_&& h,
  60. boost::shared_ptr<impl_type> const& sp,
  61. MutableBufferSequence const& bs)
  62. : async_base<
  63. Handler, beast::executor_type<stream>>(
  64. std::forward<Handler_>(h),
  65. sp->stream().get_executor())
  66. , wp_(sp)
  67. , bs_(bs)
  68. , cb_(bs)
  69. , code_(close_code::none)
  70. {
  71. (*this)({}, 0, false);
  72. }
  73. void operator()(
  74. error_code ec = {},
  75. std::size_t bytes_transferred = 0,
  76. bool cont = true)
  77. {
  78. using beast::detail::clamp;
  79. auto sp = wp_.lock();
  80. if(! sp)
  81. {
  82. ec = net::error::operation_aborted;
  83. bytes_written_ = 0;
  84. return this->complete(cont, ec, bytes_written_);
  85. }
  86. auto& impl = *sp;
  87. BOOST_ASIO_CORO_REENTER(*this)
  88. {
  89. impl.update_timer(this->get_executor());
  90. acquire_read_lock:
  91. // Acquire the read lock
  92. if(! impl.rd_block.try_lock(this))
  93. {
  94. do_suspend:
  95. BOOST_ASIO_CORO_YIELD
  96. impl.op_r_rd.emplace(std::move(*this));
  97. impl.rd_block.lock(this);
  98. BOOST_ASIO_CORO_YIELD
  99. net::post(std::move(*this));
  100. BOOST_ASSERT(impl.rd_block.is_locked(this));
  101. // VFALCO Is this check correct here?
  102. BOOST_ASSERT(! ec && impl.check_stop_now(ec));
  103. if(impl.check_stop_now(ec))
  104. {
  105. BOOST_ASSERT(ec == net::error::operation_aborted);
  106. goto upcall;
  107. }
  108. // VFALCO Should never get here
  109. // The only way to get read blocked is if
  110. // a `close_op` wrote a close frame
  111. BOOST_ASSERT(impl.wr_close);
  112. BOOST_ASSERT(impl.status_ != status::open);
  113. ec = net::error::operation_aborted;
  114. goto upcall;
  115. }
  116. else
  117. {
  118. // Make sure the stream is not closed
  119. if( impl.status_ == status::closed ||
  120. impl.status_ == status::failed)
  121. {
  122. ec = net::error::operation_aborted;
  123. goto upcall;
  124. }
  125. }
  126. // if status_ == status::closing, we want to suspend
  127. // the read operation until the close completes,
  128. // then finish the read with operation_aborted.
  129. loop:
  130. BOOST_ASSERT(impl.rd_block.is_locked(this));
  131. // See if we need to read a frame header. This
  132. // condition is structured to give the decompressor
  133. // a chance to emit the final empty deflate block
  134. //
  135. if(impl.rd_remain == 0 &&
  136. (! impl.rd_fh.fin || impl.rd_done))
  137. {
  138. // Read frame header
  139. while(! impl.parse_fh(
  140. impl.rd_fh, impl.rd_buf, result_))
  141. {
  142. if(result_)
  143. {
  144. // _Fail the WebSocket Connection_
  145. if(result_ == error::message_too_big)
  146. code_ = close_code::too_big;
  147. else
  148. code_ = close_code::protocol_error;
  149. goto close;
  150. }
  151. BOOST_ASSERT(impl.rd_block.is_locked(this));
  152. BOOST_ASIO_CORO_YIELD
  153. impl.stream().async_read_some(
  154. impl.rd_buf.prepare(read_size(
  155. impl.rd_buf, impl.rd_buf.max_size())),
  156. std::move(*this));
  157. BOOST_ASSERT(impl.rd_block.is_locked(this));
  158. impl.rd_buf.commit(bytes_transferred);
  159. if(impl.check_stop_now(ec))
  160. goto upcall;
  161. impl.reset_idle();
  162. // Allow a close operation
  163. // to acquire the read block
  164. impl.rd_block.unlock(this);
  165. if( impl.op_r_close.maybe_invoke())
  166. {
  167. // Suspend
  168. BOOST_ASSERT(impl.rd_block.is_locked());
  169. goto do_suspend;
  170. }
  171. // Acquire read block
  172. impl.rd_block.lock(this);
  173. }
  174. // Immediately apply the mask to the portion
  175. // of the buffer holding payload data.
  176. if(impl.rd_fh.len > 0 && impl.rd_fh.mask)
  177. detail::mask_inplace(buffers_prefix(
  178. clamp(impl.rd_fh.len),
  179. impl.rd_buf.data()),
  180. impl.rd_key);
  181. if(detail::is_control(impl.rd_fh.op))
  182. {
  183. // Clear this otherwise the next
  184. // frame will be considered final.
  185. impl.rd_fh.fin = false;
  186. // Handle ping frame
  187. if(impl.rd_fh.op == detail::opcode::ping)
  188. {
  189. if(impl.ctrl_cb)
  190. {
  191. if(! cont)
  192. {
  193. BOOST_ASIO_CORO_YIELD
  194. net::post(std::move(*this));
  195. BOOST_ASSERT(cont);
  196. // VFALCO call check_stop_now() here?
  197. }
  198. }
  199. {
  200. auto const b = buffers_prefix(
  201. clamp(impl.rd_fh.len),
  202. impl.rd_buf.data());
  203. auto const len = buffer_bytes(b);
  204. BOOST_ASSERT(len == impl.rd_fh.len);
  205. ping_data payload;
  206. detail::read_ping(payload, b);
  207. impl.rd_buf.consume(len);
  208. // Ignore ping when closing
  209. if(impl.status_ == status::closing)
  210. goto loop;
  211. if(impl.ctrl_cb)
  212. impl.ctrl_cb(
  213. frame_type::ping, payload);
  214. impl.rd_fb.clear();
  215. impl.template write_ping<
  216. flat_static_buffer_base>(impl.rd_fb,
  217. detail::opcode::pong, payload);
  218. }
  219. // Allow a close operation
  220. // to acquire the read block
  221. impl.rd_block.unlock(this);
  222. impl.op_r_close.maybe_invoke();
  223. // Acquire the write lock
  224. if(! impl.wr_block.try_lock(this))
  225. {
  226. BOOST_ASIO_CORO_YIELD
  227. impl.op_rd.emplace(std::move(*this));
  228. impl.wr_block.lock(this);
  229. BOOST_ASIO_CORO_YIELD
  230. net::post(std::move(*this));
  231. BOOST_ASSERT(impl.wr_block.is_locked(this));
  232. if(impl.check_stop_now(ec))
  233. goto upcall;
  234. }
  235. // Send pong
  236. BOOST_ASSERT(impl.wr_block.is_locked(this));
  237. BOOST_ASIO_CORO_YIELD
  238. net::async_write(
  239. impl.stream(), impl.rd_fb.data(),
  240. beast::detail::bind_continuation(std::move(*this)));
  241. BOOST_ASSERT(impl.wr_block.is_locked(this));
  242. if(impl.check_stop_now(ec))
  243. goto upcall;
  244. impl.wr_block.unlock(this);
  245. impl.op_close.maybe_invoke()
  246. || impl.op_idle_ping.maybe_invoke()
  247. || impl.op_ping.maybe_invoke()
  248. || impl.op_wr.maybe_invoke();
  249. goto acquire_read_lock;
  250. }
  251. // Handle pong frame
  252. if(impl.rd_fh.op == detail::opcode::pong)
  253. {
  254. // Ignore pong when closing
  255. if(! impl.wr_close && impl.ctrl_cb)
  256. {
  257. if(! cont)
  258. {
  259. BOOST_ASIO_CORO_YIELD
  260. net::post(std::move(*this));
  261. BOOST_ASSERT(cont);
  262. }
  263. }
  264. auto const cb = buffers_prefix(clamp(
  265. impl.rd_fh.len), impl.rd_buf.data());
  266. auto const len = buffer_bytes(cb);
  267. BOOST_ASSERT(len == impl.rd_fh.len);
  268. ping_data payload;
  269. detail::read_ping(payload, cb);
  270. impl.rd_buf.consume(len);
  271. // Ignore pong when closing
  272. if(! impl.wr_close && impl.ctrl_cb)
  273. impl.ctrl_cb(frame_type::pong, payload);
  274. goto loop;
  275. }
  276. // Handle close frame
  277. BOOST_ASSERT(impl.rd_fh.op == detail::opcode::close);
  278. {
  279. if(impl.ctrl_cb)
  280. {
  281. if(! cont)
  282. {
  283. BOOST_ASIO_CORO_YIELD
  284. net::post(std::move(*this));
  285. BOOST_ASSERT(cont);
  286. }
  287. }
  288. auto const cb = buffers_prefix(clamp(
  289. impl.rd_fh.len), impl.rd_buf.data());
  290. auto const len = buffer_bytes(cb);
  291. BOOST_ASSERT(len == impl.rd_fh.len);
  292. BOOST_ASSERT(! impl.rd_close);
  293. impl.rd_close = true;
  294. close_reason cr;
  295. detail::read_close(cr, cb, result_);
  296. if(result_)
  297. {
  298. // _Fail the WebSocket Connection_
  299. code_ = close_code::protocol_error;
  300. goto close;
  301. }
  302. impl.cr = cr;
  303. impl.rd_buf.consume(len);
  304. if(impl.ctrl_cb)
  305. impl.ctrl_cb(frame_type::close,
  306. impl.cr.reason);
  307. // See if we are already closing
  308. if(impl.status_ == status::closing)
  309. {
  310. // _Close the WebSocket Connection_
  311. BOOST_ASSERT(impl.wr_close);
  312. code_ = close_code::none;
  313. result_ = error::closed;
  314. goto close;
  315. }
  316. // _Start the WebSocket Closing Handshake_
  317. code_ = cr.code == close_code::none ?
  318. close_code::normal :
  319. static_cast<close_code>(cr.code);
  320. result_ = error::closed;
  321. goto close;
  322. }
  323. }
  324. if(impl.rd_fh.len == 0 && ! impl.rd_fh.fin)
  325. {
  326. // Empty non-final frame
  327. goto loop;
  328. }
  329. impl.rd_done = false;
  330. }
  331. if(! impl.rd_deflated())
  332. {
  333. if(impl.rd_remain > 0)
  334. {
  335. if(impl.rd_buf.size() == 0 && impl.rd_buf.max_size() >
  336. (std::min)(clamp(impl.rd_remain),
  337. buffer_bytes(cb_)))
  338. {
  339. // Fill the read buffer first, otherwise we
  340. // get fewer bytes at the cost of one I/O.
  341. BOOST_ASIO_CORO_YIELD
  342. impl.stream().async_read_some(
  343. impl.rd_buf.prepare(read_size(
  344. impl.rd_buf, impl.rd_buf.max_size())),
  345. std::move(*this));
  346. impl.rd_buf.commit(bytes_transferred);
  347. if(impl.check_stop_now(ec))
  348. goto upcall;
  349. impl.reset_idle();
  350. if(impl.rd_fh.mask)
  351. detail::mask_inplace(buffers_prefix(clamp(
  352. impl.rd_remain), impl.rd_buf.data()),
  353. impl.rd_key);
  354. }
  355. if(impl.rd_buf.size() > 0)
  356. {
  357. // Copy from the read buffer.
  358. // The mask was already applied.
  359. bytes_transferred = net::buffer_copy(cb_,
  360. impl.rd_buf.data(), clamp(impl.rd_remain));
  361. auto const mb = buffers_prefix(
  362. bytes_transferred, cb_);
  363. impl.rd_remain -= bytes_transferred;
  364. if(impl.rd_op == detail::opcode::text)
  365. {
  366. if(! impl.rd_utf8.write(mb) ||
  367. (impl.rd_remain == 0 && impl.rd_fh.fin &&
  368. ! impl.rd_utf8.finish()))
  369. {
  370. // _Fail the WebSocket Connection_
  371. code_ = close_code::bad_payload;
  372. result_ = error::bad_frame_payload;
  373. goto close;
  374. }
  375. }
  376. bytes_written_ += bytes_transferred;
  377. impl.rd_size += bytes_transferred;
  378. impl.rd_buf.consume(bytes_transferred);
  379. }
  380. else
  381. {
  382. // Read into caller's buffer
  383. BOOST_ASSERT(impl.rd_remain > 0);
  384. BOOST_ASSERT(buffer_bytes(cb_) > 0);
  385. BOOST_ASSERT(buffer_bytes(buffers_prefix(
  386. clamp(impl.rd_remain), cb_)) > 0);
  387. BOOST_ASIO_CORO_YIELD
  388. impl.stream().async_read_some(buffers_prefix(
  389. clamp(impl.rd_remain), cb_), std::move(*this));
  390. if(impl.check_stop_now(ec))
  391. goto upcall;
  392. impl.reset_idle();
  393. BOOST_ASSERT(bytes_transferred > 0);
  394. auto const mb = buffers_prefix(
  395. bytes_transferred, cb_);
  396. impl.rd_remain -= bytes_transferred;
  397. if(impl.rd_fh.mask)
  398. detail::mask_inplace(mb, impl.rd_key);
  399. if(impl.rd_op == detail::opcode::text)
  400. {
  401. if(! impl.rd_utf8.write(mb) ||
  402. (impl.rd_remain == 0 && impl.rd_fh.fin &&
  403. ! impl.rd_utf8.finish()))
  404. {
  405. // _Fail the WebSocket Connection_
  406. code_ = close_code::bad_payload;
  407. result_ = error::bad_frame_payload;
  408. goto close;
  409. }
  410. }
  411. bytes_written_ += bytes_transferred;
  412. impl.rd_size += bytes_transferred;
  413. }
  414. }
  415. impl.rd_done = impl.rd_remain == 0 && impl.rd_fh.fin;
  416. }
  417. else
  418. {
  419. // Read compressed message frame payload:
  420. // inflate even if rd_fh_.len == 0, otherwise we
  421. // never emit the end-of-stream deflate block.
  422. while(buffer_bytes(cb_) > 0)
  423. {
  424. if( impl.rd_remain > 0 &&
  425. impl.rd_buf.size() == 0 &&
  426. ! did_read_)
  427. {
  428. // read new
  429. BOOST_ASIO_CORO_YIELD
  430. impl.stream().async_read_some(
  431. impl.rd_buf.prepare(read_size(
  432. impl.rd_buf, impl.rd_buf.max_size())),
  433. std::move(*this));
  434. if(impl.check_stop_now(ec))
  435. goto upcall;
  436. impl.reset_idle();
  437. BOOST_ASSERT(bytes_transferred > 0);
  438. impl.rd_buf.commit(bytes_transferred);
  439. if(impl.rd_fh.mask)
  440. detail::mask_inplace(
  441. buffers_prefix(clamp(impl.rd_remain),
  442. impl.rd_buf.data()), impl.rd_key);
  443. did_read_ = true;
  444. }
  445. zlib::z_params zs;
  446. {
  447. auto const out = buffers_front(cb_);
  448. zs.next_out = out.data();
  449. zs.avail_out = out.size();
  450. BOOST_ASSERT(zs.avail_out > 0);
  451. }
  452. if(impl.rd_remain > 0)
  453. {
  454. if(impl.rd_buf.size() > 0)
  455. {
  456. // use what's there
  457. auto const in = buffers_prefix(
  458. clamp(impl.rd_remain), buffers_front(
  459. impl.rd_buf.data()));
  460. zs.avail_in = in.size();
  461. zs.next_in = in.data();
  462. }
  463. else
  464. {
  465. break;
  466. }
  467. }
  468. else if(impl.rd_fh.fin)
  469. {
  470. // append the empty block codes
  471. std::uint8_t constexpr
  472. empty_block[4] = { 0x00, 0x00, 0xff, 0xff };
  473. zs.next_in = empty_block;
  474. zs.avail_in = sizeof(empty_block);
  475. impl.inflate(zs, zlib::Flush::sync, ec);
  476. if(! ec)
  477. {
  478. // https://github.com/madler/zlib/issues/280
  479. if(zs.total_out > 0)
  480. ec = error::partial_deflate_block;
  481. }
  482. if(impl.check_stop_now(ec))
  483. goto upcall;
  484. impl.do_context_takeover_read(impl.role);
  485. impl.rd_done = true;
  486. break;
  487. }
  488. else
  489. {
  490. break;
  491. }
  492. impl.inflate(zs, zlib::Flush::sync, ec);
  493. if(impl.check_stop_now(ec))
  494. goto upcall;
  495. if(impl.rd_msg_max && beast::detail::sum_exceeds(
  496. impl.rd_size, zs.total_out, impl.rd_msg_max))
  497. {
  498. // _Fail the WebSocket Connection_
  499. code_ = close_code::too_big;
  500. result_ = error::message_too_big;
  501. goto close;
  502. }
  503. cb_.consume(zs.total_out);
  504. impl.rd_size += zs.total_out;
  505. impl.rd_remain -= zs.total_in;
  506. impl.rd_buf.consume(zs.total_in);
  507. bytes_written_ += zs.total_out;
  508. }
  509. if(impl.rd_op == detail::opcode::text)
  510. {
  511. // check utf8
  512. if(! impl.rd_utf8.write(
  513. buffers_prefix(bytes_written_, bs_)) || (
  514. impl.rd_done && ! impl.rd_utf8.finish()))
  515. {
  516. // _Fail the WebSocket Connection_
  517. code_ = close_code::bad_payload;
  518. result_ = error::bad_frame_payload;
  519. goto close;
  520. }
  521. }
  522. }
  523. goto upcall;
  524. close:
  525. // Acquire the write lock
  526. if(! impl.wr_block.try_lock(this))
  527. {
  528. BOOST_ASIO_CORO_YIELD
  529. impl.op_rd.emplace(std::move(*this));
  530. impl.wr_block.lock(this);
  531. BOOST_ASIO_CORO_YIELD
  532. net::post(std::move(*this));
  533. BOOST_ASSERT(impl.wr_block.is_locked(this));
  534. if(impl.check_stop_now(ec))
  535. goto upcall;
  536. }
  537. impl.change_status(status::closing);
  538. if(! impl.wr_close)
  539. {
  540. impl.wr_close = true;
  541. // Serialize close frame
  542. impl.rd_fb.clear();
  543. impl.template write_close<
  544. flat_static_buffer_base>(
  545. impl.rd_fb, code_);
  546. // Send close frame
  547. BOOST_ASSERT(impl.wr_block.is_locked(this));
  548. BOOST_ASIO_CORO_YIELD
  549. net::async_write(impl.stream(), impl.rd_fb.data(),
  550. beast::detail::bind_continuation(std::move(*this)));
  551. BOOST_ASSERT(impl.wr_block.is_locked(this));
  552. if(impl.check_stop_now(ec))
  553. goto upcall;
  554. }
  555. // Teardown
  556. using beast::websocket::async_teardown;
  557. BOOST_ASSERT(impl.wr_block.is_locked(this));
  558. BOOST_ASIO_CORO_YIELD
  559. async_teardown(impl.role, impl.stream(),
  560. beast::detail::bind_continuation(std::move(*this)));
  561. BOOST_ASSERT(impl.wr_block.is_locked(this));
  562. if(ec == net::error::eof)
  563. {
  564. // Rationale:
  565. // http://stackoverflow.com/questions/25587403/boost-asio-ssl-async-shutdown-always-finishes-with-an-error
  566. ec = {};
  567. }
  568. if(! ec)
  569. ec = result_;
  570. if(ec && ec != error::closed)
  571. impl.change_status(status::failed);
  572. else
  573. impl.change_status(status::closed);
  574. impl.close();
  575. upcall:
  576. impl.rd_block.try_unlock(this);
  577. impl.op_r_close.maybe_invoke();
  578. if(impl.wr_block.try_unlock(this))
  579. impl.op_close.maybe_invoke()
  580. || impl.op_idle_ping.maybe_invoke()
  581. || impl.op_ping.maybe_invoke()
  582. || impl.op_wr.maybe_invoke();
  583. this->complete(cont, ec, bytes_written_);
  584. }
  585. }
  586. };
  587. //------------------------------------------------------------------------------
  588. template<class NextLayer, bool deflateSupported>
  589. template<class Handler, class DynamicBuffer>
  590. class stream<NextLayer, deflateSupported>::read_op
  591. : public beast::async_base<
  592. Handler, beast::executor_type<stream>>
  593. , public net::coroutine
  594. {
  595. boost::weak_ptr<impl_type> wp_;
  596. DynamicBuffer& b_;
  597. std::size_t limit_;
  598. std::size_t bytes_written_ = 0;
  599. bool some_;
  600. public:
  601. template<class Handler_>
  602. read_op(
  603. Handler_&& h,
  604. boost::shared_ptr<impl_type> const& sp,
  605. DynamicBuffer& b,
  606. std::size_t limit,
  607. bool some)
  608. : async_base<Handler,
  609. beast::executor_type<stream>>(
  610. std::forward<Handler_>(h),
  611. sp->stream().get_executor())
  612. , wp_(sp)
  613. , b_(b)
  614. , limit_(limit ? limit : (
  615. std::numeric_limits<std::size_t>::max)())
  616. , some_(some)
  617. {
  618. (*this)({}, 0, false);
  619. }
  620. void operator()(
  621. error_code ec = {},
  622. std::size_t bytes_transferred = 0,
  623. bool cont = true)
  624. {
  625. using beast::detail::clamp;
  626. auto sp = wp_.lock();
  627. if(! sp)
  628. {
  629. ec = net::error::operation_aborted;
  630. bytes_written_ = 0;
  631. return this->complete(cont, ec, bytes_written_);
  632. }
  633. auto& impl = *sp;
  634. using mutable_buffers_type = typename
  635. DynamicBuffer::mutable_buffers_type;
  636. boost::optional<mutable_buffers_type> mb;
  637. BOOST_ASIO_CORO_REENTER(*this)
  638. {
  639. do
  640. {
  641. mb = beast::detail::dynamic_buffer_prepare(b_,
  642. clamp(impl.read_size_hint_db(b_), limit_),
  643. ec, error::buffer_overflow);
  644. if(impl.check_stop_now(ec))
  645. goto upcall;
  646. // VFALCO TODO use boost::beast::bind_continuation
  647. BOOST_ASIO_CORO_YIELD
  648. read_some_op<read_op, mutable_buffers_type>(
  649. std::move(*this), sp, *mb);
  650. b_.commit(bytes_transferred);
  651. bytes_written_ += bytes_transferred;
  652. if(ec)
  653. goto upcall;
  654. }
  655. while(! some_ && ! impl.rd_done);
  656. upcall:
  657. this->complete(cont, ec, bytes_written_);
  658. }
  659. }
  660. };
  661. template<class NextLayer, bool deflateSupported>
  662. struct stream<NextLayer, deflateSupported>::
  663. run_read_some_op
  664. {
  665. template<
  666. class ReadHandler,
  667. class MutableBufferSequence>
  668. void
  669. operator()(
  670. ReadHandler&& h,
  671. boost::shared_ptr<impl_type> const& sp,
  672. MutableBufferSequence const& b)
  673. {
  674. // If you get an error on the following line it means
  675. // that your handler does not meet the documented type
  676. // requirements for the handler.
  677. static_assert(
  678. beast::detail::is_invocable<ReadHandler,
  679. void(error_code, std::size_t)>::value,
  680. "ReadHandler type requirements not met");
  681. read_some_op<
  682. typename std::decay<ReadHandler>::type,
  683. MutableBufferSequence>(
  684. std::forward<ReadHandler>(h),
  685. sp,
  686. b);
  687. }
  688. };
  689. template<class NextLayer, bool deflateSupported>
  690. struct stream<NextLayer, deflateSupported>::
  691. run_read_op
  692. {
  693. template<
  694. class ReadHandler,
  695. class DynamicBuffer>
  696. void
  697. operator()(
  698. ReadHandler&& h,
  699. boost::shared_ptr<impl_type> const& sp,
  700. DynamicBuffer* b,
  701. std::size_t limit,
  702. bool some)
  703. {
  704. // If you get an error on the following line it means
  705. // that your handler does not meet the documented type
  706. // requirements for the handler.
  707. static_assert(
  708. beast::detail::is_invocable<ReadHandler,
  709. void(error_code, std::size_t)>::value,
  710. "ReadHandler type requirements not met");
  711. read_op<
  712. typename std::decay<ReadHandler>::type,
  713. DynamicBuffer>(
  714. std::forward<ReadHandler>(h),
  715. sp,
  716. *b,
  717. limit,
  718. some);
  719. }
  720. };
  721. //------------------------------------------------------------------------------
  722. template<class NextLayer, bool deflateSupported>
  723. template<class DynamicBuffer>
  724. std::size_t
  725. stream<NextLayer, deflateSupported>::
  726. read(DynamicBuffer& buffer)
  727. {
  728. static_assert(is_sync_stream<next_layer_type>::value,
  729. "SyncStream type requirements not met");
  730. static_assert(
  731. net::is_dynamic_buffer<DynamicBuffer>::value,
  732. "DynamicBuffer type requirements not met");
  733. error_code ec;
  734. auto const bytes_written = read(buffer, ec);
  735. if(ec)
  736. BOOST_THROW_EXCEPTION(system_error{ec});
  737. return bytes_written;
  738. }
  739. template<class NextLayer, bool deflateSupported>
  740. template<class DynamicBuffer>
  741. std::size_t
  742. stream<NextLayer, deflateSupported>::
  743. read(DynamicBuffer& buffer, error_code& ec)
  744. {
  745. static_assert(is_sync_stream<next_layer_type>::value,
  746. "SyncStream type requirements not met");
  747. static_assert(
  748. net::is_dynamic_buffer<DynamicBuffer>::value,
  749. "DynamicBuffer type requirements not met");
  750. std::size_t bytes_written = 0;
  751. do
  752. {
  753. bytes_written += read_some(buffer, 0, ec);
  754. if(ec)
  755. return bytes_written;
  756. }
  757. while(! is_message_done());
  758. return bytes_written;
  759. }
  760. template<class NextLayer, bool deflateSupported>
  761. template<class DynamicBuffer, class ReadHandler>
  762. BOOST_BEAST_ASYNC_RESULT2(ReadHandler)
  763. stream<NextLayer, deflateSupported>::
  764. async_read(DynamicBuffer& buffer, ReadHandler&& handler)
  765. {
  766. static_assert(is_async_stream<next_layer_type>::value,
  767. "AsyncStream type requirements not met");
  768. static_assert(
  769. net::is_dynamic_buffer<DynamicBuffer>::value,
  770. "DynamicBuffer type requirements not met");
  771. return net::async_initiate<
  772. ReadHandler,
  773. void(error_code, std::size_t)>(
  774. run_read_op{},
  775. handler,
  776. impl_,
  777. &buffer,
  778. 0,
  779. false);
  780. }
  781. //------------------------------------------------------------------------------
  782. template<class NextLayer, bool deflateSupported>
  783. template<class DynamicBuffer>
  784. std::size_t
  785. stream<NextLayer, deflateSupported>::
  786. read_some(
  787. DynamicBuffer& buffer,
  788. std::size_t limit)
  789. {
  790. static_assert(is_sync_stream<next_layer_type>::value,
  791. "SyncStream type requirements not met");
  792. static_assert(
  793. net::is_dynamic_buffer<DynamicBuffer>::value,
  794. "DynamicBuffer type requirements not met");
  795. error_code ec;
  796. auto const bytes_written =
  797. read_some(buffer, limit, ec);
  798. if(ec)
  799. BOOST_THROW_EXCEPTION(system_error{ec});
  800. return bytes_written;
  801. }
  802. template<class NextLayer, bool deflateSupported>
  803. template<class DynamicBuffer>
  804. std::size_t
  805. stream<NextLayer, deflateSupported>::
  806. read_some(
  807. DynamicBuffer& buffer,
  808. std::size_t limit,
  809. error_code& ec)
  810. {
  811. static_assert(is_sync_stream<next_layer_type>::value,
  812. "SyncStream type requirements not met");
  813. static_assert(
  814. net::is_dynamic_buffer<DynamicBuffer>::value,
  815. "DynamicBuffer type requirements not met");
  816. using beast::detail::clamp;
  817. if(! limit)
  818. limit = (std::numeric_limits<std::size_t>::max)();
  819. auto const size =
  820. clamp(read_size_hint(buffer), limit);
  821. BOOST_ASSERT(size > 0);
  822. auto mb = beast::detail::dynamic_buffer_prepare(
  823. buffer, size, ec, error::buffer_overflow);
  824. if(impl_->check_stop_now(ec))
  825. return 0;
  826. auto const bytes_written = read_some(*mb, ec);
  827. buffer.commit(bytes_written);
  828. return bytes_written;
  829. }
  830. template<class NextLayer, bool deflateSupported>
  831. template<class DynamicBuffer, class ReadHandler>
  832. BOOST_BEAST_ASYNC_RESULT2(ReadHandler)
  833. stream<NextLayer, deflateSupported>::
  834. async_read_some(
  835. DynamicBuffer& buffer,
  836. std::size_t limit,
  837. ReadHandler&& handler)
  838. {
  839. static_assert(is_async_stream<next_layer_type>::value,
  840. "AsyncStream type requirements not met");
  841. static_assert(
  842. net::is_dynamic_buffer<DynamicBuffer>::value,
  843. "DynamicBuffer type requirements not met");
  844. return net::async_initiate<
  845. ReadHandler,
  846. void(error_code, std::size_t)>(
  847. run_read_op{},
  848. handler,
  849. impl_,
  850. &buffer,
  851. limit,
  852. true);
  853. }
  854. //------------------------------------------------------------------------------
  855. template<class NextLayer, bool deflateSupported>
  856. template<class MutableBufferSequence>
  857. std::size_t
  858. stream<NextLayer, deflateSupported>::
  859. read_some(
  860. MutableBufferSequence const& buffers)
  861. {
  862. static_assert(is_sync_stream<next_layer_type>::value,
  863. "SyncStream type requirements not met");
  864. static_assert(net::is_mutable_buffer_sequence<
  865. MutableBufferSequence>::value,
  866. "MutableBufferSequence type requirements not met");
  867. error_code ec;
  868. auto const bytes_written = read_some(buffers, ec);
  869. if(ec)
  870. BOOST_THROW_EXCEPTION(system_error{ec});
  871. return bytes_written;
  872. }
  873. template<class NextLayer, bool deflateSupported>
  874. template<class MutableBufferSequence>
  875. std::size_t
  876. stream<NextLayer, deflateSupported>::
  877. read_some(
  878. MutableBufferSequence const& buffers,
  879. error_code& ec)
  880. {
  881. static_assert(is_sync_stream<next_layer_type>::value,
  882. "SyncStream type requirements not met");
  883. static_assert(net::is_mutable_buffer_sequence<
  884. MutableBufferSequence>::value,
  885. "MutableBufferSequence type requirements not met");
  886. using beast::detail::clamp;
  887. auto& impl = *impl_;
  888. close_code code{};
  889. std::size_t bytes_written = 0;
  890. ec = {};
  891. // Make sure the stream is open
  892. if(impl.check_stop_now(ec))
  893. return bytes_written;
  894. loop:
  895. // See if we need to read a frame header. This
  896. // condition is structured to give the decompressor
  897. // a chance to emit the final empty deflate block
  898. //
  899. if(impl.rd_remain == 0 && (
  900. ! impl.rd_fh.fin || impl.rd_done))
  901. {
  902. // Read frame header
  903. error_code result;
  904. while(! impl.parse_fh(impl.rd_fh, impl.rd_buf, result))
  905. {
  906. if(result)
  907. {
  908. // _Fail the WebSocket Connection_
  909. if(result == error::message_too_big)
  910. code = close_code::too_big;
  911. else
  912. code = close_code::protocol_error;
  913. do_fail(code, result, ec);
  914. return bytes_written;
  915. }
  916. auto const bytes_transferred =
  917. impl.stream().read_some(
  918. impl.rd_buf.prepare(read_size(
  919. impl.rd_buf, impl.rd_buf.max_size())),
  920. ec);
  921. impl.rd_buf.commit(bytes_transferred);
  922. if(impl.check_stop_now(ec))
  923. return bytes_written;
  924. }
  925. // Immediately apply the mask to the portion
  926. // of the buffer holding payload data.
  927. if(impl.rd_fh.len > 0 && impl.rd_fh.mask)
  928. detail::mask_inplace(buffers_prefix(
  929. clamp(impl.rd_fh.len), impl.rd_buf.data()),
  930. impl.rd_key);
  931. if(detail::is_control(impl.rd_fh.op))
  932. {
  933. // Get control frame payload
  934. auto const b = buffers_prefix(
  935. clamp(impl.rd_fh.len), impl.rd_buf.data());
  936. auto const len = buffer_bytes(b);
  937. BOOST_ASSERT(len == impl.rd_fh.len);
  938. // Clear this otherwise the next
  939. // frame will be considered final.
  940. impl.rd_fh.fin = false;
  941. // Handle ping frame
  942. if(impl.rd_fh.op == detail::opcode::ping)
  943. {
  944. ping_data payload;
  945. detail::read_ping(payload, b);
  946. impl.rd_buf.consume(len);
  947. if(impl.wr_close)
  948. {
  949. // Ignore ping when closing
  950. goto loop;
  951. }
  952. if(impl.ctrl_cb)
  953. impl.ctrl_cb(frame_type::ping, payload);
  954. detail::frame_buffer fb;
  955. impl.template write_ping<flat_static_buffer_base>(fb,
  956. detail::opcode::pong, payload);
  957. net::write(impl.stream(), fb.data(), ec);
  958. if(impl.check_stop_now(ec))
  959. return bytes_written;
  960. goto loop;
  961. }
  962. // Handle pong frame
  963. if(impl.rd_fh.op == detail::opcode::pong)
  964. {
  965. ping_data payload;
  966. detail::read_ping(payload, b);
  967. impl.rd_buf.consume(len);
  968. if(impl.ctrl_cb)
  969. impl.ctrl_cb(frame_type::pong, payload);
  970. goto loop;
  971. }
  972. // Handle close frame
  973. BOOST_ASSERT(impl.rd_fh.op == detail::opcode::close);
  974. {
  975. BOOST_ASSERT(! impl.rd_close);
  976. impl.rd_close = true;
  977. close_reason cr;
  978. detail::read_close(cr, b, result);
  979. if(result)
  980. {
  981. // _Fail the WebSocket Connection_
  982. do_fail(close_code::protocol_error,
  983. result, ec);
  984. return bytes_written;
  985. }
  986. impl.cr = cr;
  987. impl.rd_buf.consume(len);
  988. if(impl.ctrl_cb)
  989. impl.ctrl_cb(frame_type::close, impl.cr.reason);
  990. BOOST_ASSERT(! impl.wr_close);
  991. // _Start the WebSocket Closing Handshake_
  992. do_fail(
  993. cr.code == close_code::none ?
  994. close_code::normal :
  995. static_cast<close_code>(cr.code),
  996. error::closed, ec);
  997. return bytes_written;
  998. }
  999. }
  1000. if(impl.rd_fh.len == 0 && ! impl.rd_fh.fin)
  1001. {
  1002. // Empty non-final frame
  1003. goto loop;
  1004. }
  1005. impl.rd_done = false;
  1006. }
  1007. else
  1008. {
  1009. ec = {};
  1010. }
  1011. if(! impl.rd_deflated())
  1012. {
  1013. if(impl.rd_remain > 0)
  1014. {
  1015. if(impl.rd_buf.size() == 0 && impl.rd_buf.max_size() >
  1016. (std::min)(clamp(impl.rd_remain),
  1017. buffer_bytes(buffers)))
  1018. {
  1019. // Fill the read buffer first, otherwise we
  1020. // get fewer bytes at the cost of one I/O.
  1021. impl.rd_buf.commit(impl.stream().read_some(
  1022. impl.rd_buf.prepare(read_size(impl.rd_buf,
  1023. impl.rd_buf.max_size())), ec));
  1024. if(impl.check_stop_now(ec))
  1025. return bytes_written;
  1026. if(impl.rd_fh.mask)
  1027. detail::mask_inplace(
  1028. buffers_prefix(clamp(impl.rd_remain),
  1029. impl.rd_buf.data()), impl.rd_key);
  1030. }
  1031. if(impl.rd_buf.size() > 0)
  1032. {
  1033. // Copy from the read buffer.
  1034. // The mask was already applied.
  1035. auto const bytes_transferred = net::buffer_copy(
  1036. buffers, impl.rd_buf.data(),
  1037. clamp(impl.rd_remain));
  1038. auto const mb = buffers_prefix(
  1039. bytes_transferred, buffers);
  1040. impl.rd_remain -= bytes_transferred;
  1041. if(impl.rd_op == detail::opcode::text)
  1042. {
  1043. if(! impl.rd_utf8.write(mb) ||
  1044. (impl.rd_remain == 0 && impl.rd_fh.fin &&
  1045. ! impl.rd_utf8.finish()))
  1046. {
  1047. // _Fail the WebSocket Connection_
  1048. do_fail(close_code::bad_payload,
  1049. error::bad_frame_payload, ec);
  1050. return bytes_written;
  1051. }
  1052. }
  1053. bytes_written += bytes_transferred;
  1054. impl.rd_size += bytes_transferred;
  1055. impl.rd_buf.consume(bytes_transferred);
  1056. }
  1057. else
  1058. {
  1059. // Read into caller's buffer
  1060. BOOST_ASSERT(impl.rd_remain > 0);
  1061. BOOST_ASSERT(buffer_bytes(buffers) > 0);
  1062. BOOST_ASSERT(buffer_bytes(buffers_prefix(
  1063. clamp(impl.rd_remain), buffers)) > 0);
  1064. auto const bytes_transferred =
  1065. impl.stream().read_some(buffers_prefix(
  1066. clamp(impl.rd_remain), buffers), ec);
  1067. // VFALCO What if some bytes were written?
  1068. if(impl.check_stop_now(ec))
  1069. return bytes_written;
  1070. BOOST_ASSERT(bytes_transferred > 0);
  1071. auto const mb = buffers_prefix(
  1072. bytes_transferred, buffers);
  1073. impl.rd_remain -= bytes_transferred;
  1074. if(impl.rd_fh.mask)
  1075. detail::mask_inplace(mb, impl.rd_key);
  1076. if(impl.rd_op == detail::opcode::text)
  1077. {
  1078. if(! impl.rd_utf8.write(mb) ||
  1079. (impl.rd_remain == 0 && impl.rd_fh.fin &&
  1080. ! impl.rd_utf8.finish()))
  1081. {
  1082. // _Fail the WebSocket Connection_
  1083. do_fail(close_code::bad_payload,
  1084. error::bad_frame_payload, ec);
  1085. return bytes_written;
  1086. }
  1087. }
  1088. bytes_written += bytes_transferred;
  1089. impl.rd_size += bytes_transferred;
  1090. }
  1091. }
  1092. impl.rd_done = impl.rd_remain == 0 && impl.rd_fh.fin;
  1093. }
  1094. else
  1095. {
  1096. // Read compressed message frame payload:
  1097. // inflate even if rd_fh_.len == 0, otherwise we
  1098. // never emit the end-of-stream deflate block.
  1099. //
  1100. bool did_read = false;
  1101. buffers_suffix<MutableBufferSequence> cb(buffers);
  1102. while(buffer_bytes(cb) > 0)
  1103. {
  1104. zlib::z_params zs;
  1105. {
  1106. auto const out = beast::buffers_front(cb);
  1107. zs.next_out = out.data();
  1108. zs.avail_out = out.size();
  1109. BOOST_ASSERT(zs.avail_out > 0);
  1110. }
  1111. if(impl.rd_remain > 0)
  1112. {
  1113. if(impl.rd_buf.size() > 0)
  1114. {
  1115. // use what's there
  1116. auto const in = buffers_prefix(
  1117. clamp(impl.rd_remain), beast::buffers_front(
  1118. impl.rd_buf.data()));
  1119. zs.avail_in = in.size();
  1120. zs.next_in = in.data();
  1121. }
  1122. else if(! did_read)
  1123. {
  1124. // read new
  1125. auto const bytes_transferred =
  1126. impl.stream().read_some(
  1127. impl.rd_buf.prepare(read_size(
  1128. impl.rd_buf, impl.rd_buf.max_size())),
  1129. ec);
  1130. if(impl.check_stop_now(ec))
  1131. return bytes_written;
  1132. BOOST_ASSERT(bytes_transferred > 0);
  1133. impl.rd_buf.commit(bytes_transferred);
  1134. if(impl.rd_fh.mask)
  1135. detail::mask_inplace(
  1136. buffers_prefix(clamp(impl.rd_remain),
  1137. impl.rd_buf.data()), impl.rd_key);
  1138. auto const in = buffers_prefix(
  1139. clamp(impl.rd_remain), buffers_front(
  1140. impl.rd_buf.data()));
  1141. zs.avail_in = in.size();
  1142. zs.next_in = in.data();
  1143. did_read = true;
  1144. }
  1145. else
  1146. {
  1147. break;
  1148. }
  1149. }
  1150. else if(impl.rd_fh.fin)
  1151. {
  1152. // append the empty block codes
  1153. static std::uint8_t constexpr
  1154. empty_block[4] = {
  1155. 0x00, 0x00, 0xff, 0xff };
  1156. zs.next_in = empty_block;
  1157. zs.avail_in = sizeof(empty_block);
  1158. impl.inflate(zs, zlib::Flush::sync, ec);
  1159. if(! ec)
  1160. {
  1161. // https://github.com/madler/zlib/issues/280
  1162. if(zs.total_out > 0)
  1163. ec = error::partial_deflate_block;
  1164. }
  1165. if(impl.check_stop_now(ec))
  1166. return bytes_written;
  1167. impl.do_context_takeover_read(impl.role);
  1168. impl.rd_done = true;
  1169. break;
  1170. }
  1171. else
  1172. {
  1173. break;
  1174. }
  1175. impl.inflate(zs, zlib::Flush::sync, ec);
  1176. if(impl.check_stop_now(ec))
  1177. return bytes_written;
  1178. if(impl.rd_msg_max && beast::detail::sum_exceeds(
  1179. impl.rd_size, zs.total_out, impl.rd_msg_max))
  1180. {
  1181. do_fail(close_code::too_big,
  1182. error::message_too_big, ec);
  1183. return bytes_written;
  1184. }
  1185. cb.consume(zs.total_out);
  1186. impl.rd_size += zs.total_out;
  1187. impl.rd_remain -= zs.total_in;
  1188. impl.rd_buf.consume(zs.total_in);
  1189. bytes_written += zs.total_out;
  1190. }
  1191. if(impl.rd_op == detail::opcode::text)
  1192. {
  1193. // check utf8
  1194. if(! impl.rd_utf8.write(beast::buffers_prefix(
  1195. bytes_written, buffers)) || (
  1196. impl.rd_done && ! impl.rd_utf8.finish()))
  1197. {
  1198. // _Fail the WebSocket Connection_
  1199. do_fail(close_code::bad_payload,
  1200. error::bad_frame_payload, ec);
  1201. return bytes_written;
  1202. }
  1203. }
  1204. }
  1205. return bytes_written;
  1206. }
  1207. template<class NextLayer, bool deflateSupported>
  1208. template<class MutableBufferSequence, class ReadHandler>
  1209. BOOST_BEAST_ASYNC_RESULT2(ReadHandler)
  1210. stream<NextLayer, deflateSupported>::
  1211. async_read_some(
  1212. MutableBufferSequence const& buffers,
  1213. ReadHandler&& handler)
  1214. {
  1215. static_assert(is_async_stream<next_layer_type>::value,
  1216. "AsyncStream type requirements not met");
  1217. static_assert(net::is_mutable_buffer_sequence<
  1218. MutableBufferSequence>::value,
  1219. "MutableBufferSequence type requirements not met");
  1220. return net::async_initiate<
  1221. ReadHandler,
  1222. void(error_code, std::size_t)>(
  1223. run_read_some_op{},
  1224. handler,
  1225. impl_,
  1226. buffers);
  1227. }
  1228. } // websocket
  1229. } // beast
  1230. } // boost
  1231. #endif