read.hpp 48 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 asio::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 asio::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_ASIO_CORO_REENTER(*this)
  637. {
  638. do
  639. {
  640. // VFALCO TODO use boost::beast::bind_continuation
  641. BOOST_ASIO_CORO_YIELD
  642. {
  643. auto mb = beast::detail::dynamic_buffer_prepare(b_,
  644. clamp(impl.read_size_hint_db(b_), limit_),
  645. ec, error::buffer_overflow);
  646. if(impl.check_stop_now(ec))
  647. goto upcall;
  648. read_some_op<read_op, mutable_buffers_type>(
  649. std::move(*this), sp, *mb);
  650. }
  651. b_.commit(bytes_transferred);
  652. bytes_written_ += bytes_transferred;
  653. if(ec)
  654. goto upcall;
  655. }
  656. while(! some_ && ! impl.rd_done);
  657. upcall:
  658. this->complete(cont, ec, bytes_written_);
  659. }
  660. }
  661. };
  662. template<class NextLayer, bool deflateSupported>
  663. struct stream<NextLayer, deflateSupported>::
  664. run_read_some_op
  665. {
  666. template<
  667. class ReadHandler,
  668. class MutableBufferSequence>
  669. void
  670. operator()(
  671. ReadHandler&& h,
  672. boost::shared_ptr<impl_type> const& sp,
  673. MutableBufferSequence const& b)
  674. {
  675. // If you get an error on the following line it means
  676. // that your handler does not meet the documented type
  677. // requirements for the handler.
  678. static_assert(
  679. beast::detail::is_invocable<ReadHandler,
  680. void(error_code, std::size_t)>::value,
  681. "ReadHandler type requirements not met");
  682. read_some_op<
  683. typename std::decay<ReadHandler>::type,
  684. MutableBufferSequence>(
  685. std::forward<ReadHandler>(h),
  686. sp,
  687. b);
  688. }
  689. };
  690. template<class NextLayer, bool deflateSupported>
  691. struct stream<NextLayer, deflateSupported>::
  692. run_read_op
  693. {
  694. template<
  695. class ReadHandler,
  696. class DynamicBuffer>
  697. void
  698. operator()(
  699. ReadHandler&& h,
  700. boost::shared_ptr<impl_type> const& sp,
  701. DynamicBuffer* b,
  702. std::size_t limit,
  703. bool some)
  704. {
  705. // If you get an error on the following line it means
  706. // that your handler does not meet the documented type
  707. // requirements for the handler.
  708. static_assert(
  709. beast::detail::is_invocable<ReadHandler,
  710. void(error_code, std::size_t)>::value,
  711. "ReadHandler type requirements not met");
  712. read_op<
  713. typename std::decay<ReadHandler>::type,
  714. DynamicBuffer>(
  715. std::forward<ReadHandler>(h),
  716. sp,
  717. *b,
  718. limit,
  719. some);
  720. }
  721. };
  722. //------------------------------------------------------------------------------
  723. template<class NextLayer, bool deflateSupported>
  724. template<class DynamicBuffer>
  725. std::size_t
  726. stream<NextLayer, deflateSupported>::
  727. read(DynamicBuffer& buffer)
  728. {
  729. static_assert(is_sync_stream<next_layer_type>::value,
  730. "SyncStream type requirements not met");
  731. static_assert(
  732. net::is_dynamic_buffer<DynamicBuffer>::value,
  733. "DynamicBuffer type requirements not met");
  734. error_code ec;
  735. auto const bytes_written = read(buffer, ec);
  736. if(ec)
  737. BOOST_THROW_EXCEPTION(system_error{ec});
  738. return bytes_written;
  739. }
  740. template<class NextLayer, bool deflateSupported>
  741. template<class DynamicBuffer>
  742. std::size_t
  743. stream<NextLayer, deflateSupported>::
  744. read(DynamicBuffer& buffer, error_code& ec)
  745. {
  746. static_assert(is_sync_stream<next_layer_type>::value,
  747. "SyncStream type requirements not met");
  748. static_assert(
  749. net::is_dynamic_buffer<DynamicBuffer>::value,
  750. "DynamicBuffer type requirements not met");
  751. std::size_t bytes_written = 0;
  752. do
  753. {
  754. bytes_written += read_some(buffer, 0, ec);
  755. if(ec)
  756. return bytes_written;
  757. }
  758. while(! is_message_done());
  759. return bytes_written;
  760. }
  761. template<class NextLayer, bool deflateSupported>
  762. template<class DynamicBuffer, class ReadHandler>
  763. BOOST_BEAST_ASYNC_RESULT2(ReadHandler)
  764. stream<NextLayer, deflateSupported>::
  765. async_read(DynamicBuffer& buffer, ReadHandler&& handler)
  766. {
  767. static_assert(is_async_stream<next_layer_type>::value,
  768. "AsyncStream type requirements not met");
  769. static_assert(
  770. net::is_dynamic_buffer<DynamicBuffer>::value,
  771. "DynamicBuffer type requirements not met");
  772. return net::async_initiate<
  773. ReadHandler,
  774. void(error_code, std::size_t)>(
  775. run_read_op{},
  776. handler,
  777. impl_,
  778. &buffer,
  779. 0,
  780. false);
  781. }
  782. //------------------------------------------------------------------------------
  783. template<class NextLayer, bool deflateSupported>
  784. template<class DynamicBuffer>
  785. std::size_t
  786. stream<NextLayer, deflateSupported>::
  787. read_some(
  788. DynamicBuffer& buffer,
  789. std::size_t limit)
  790. {
  791. static_assert(is_sync_stream<next_layer_type>::value,
  792. "SyncStream type requirements not met");
  793. static_assert(
  794. net::is_dynamic_buffer<DynamicBuffer>::value,
  795. "DynamicBuffer type requirements not met");
  796. error_code ec;
  797. auto const bytes_written =
  798. read_some(buffer, limit, ec);
  799. if(ec)
  800. BOOST_THROW_EXCEPTION(system_error{ec});
  801. return bytes_written;
  802. }
  803. template<class NextLayer, bool deflateSupported>
  804. template<class DynamicBuffer>
  805. std::size_t
  806. stream<NextLayer, deflateSupported>::
  807. read_some(
  808. DynamicBuffer& buffer,
  809. std::size_t limit,
  810. error_code& ec)
  811. {
  812. static_assert(is_sync_stream<next_layer_type>::value,
  813. "SyncStream type requirements not met");
  814. static_assert(
  815. net::is_dynamic_buffer<DynamicBuffer>::value,
  816. "DynamicBuffer type requirements not met");
  817. using beast::detail::clamp;
  818. if(! limit)
  819. limit = (std::numeric_limits<std::size_t>::max)();
  820. auto const size =
  821. clamp(read_size_hint(buffer), limit);
  822. BOOST_ASSERT(size > 0);
  823. auto mb = beast::detail::dynamic_buffer_prepare(
  824. buffer, size, ec, error::buffer_overflow);
  825. if(impl_->check_stop_now(ec))
  826. return 0;
  827. auto const bytes_written = read_some(*mb, ec);
  828. buffer.commit(bytes_written);
  829. return bytes_written;
  830. }
  831. template<class NextLayer, bool deflateSupported>
  832. template<class DynamicBuffer, class ReadHandler>
  833. BOOST_BEAST_ASYNC_RESULT2(ReadHandler)
  834. stream<NextLayer, deflateSupported>::
  835. async_read_some(
  836. DynamicBuffer& buffer,
  837. std::size_t limit,
  838. ReadHandler&& handler)
  839. {
  840. static_assert(is_async_stream<next_layer_type>::value,
  841. "AsyncStream type requirements not met");
  842. static_assert(
  843. net::is_dynamic_buffer<DynamicBuffer>::value,
  844. "DynamicBuffer type requirements not met");
  845. return net::async_initiate<
  846. ReadHandler,
  847. void(error_code, std::size_t)>(
  848. run_read_op{},
  849. handler,
  850. impl_,
  851. &buffer,
  852. limit,
  853. true);
  854. }
  855. //------------------------------------------------------------------------------
  856. template<class NextLayer, bool deflateSupported>
  857. template<class MutableBufferSequence>
  858. std::size_t
  859. stream<NextLayer, deflateSupported>::
  860. read_some(
  861. MutableBufferSequence const& buffers)
  862. {
  863. static_assert(is_sync_stream<next_layer_type>::value,
  864. "SyncStream type requirements not met");
  865. static_assert(net::is_mutable_buffer_sequence<
  866. MutableBufferSequence>::value,
  867. "MutableBufferSequence type requirements not met");
  868. error_code ec;
  869. auto const bytes_written = read_some(buffers, ec);
  870. if(ec)
  871. BOOST_THROW_EXCEPTION(system_error{ec});
  872. return bytes_written;
  873. }
  874. template<class NextLayer, bool deflateSupported>
  875. template<class MutableBufferSequence>
  876. std::size_t
  877. stream<NextLayer, deflateSupported>::
  878. read_some(
  879. MutableBufferSequence const& buffers,
  880. error_code& ec)
  881. {
  882. static_assert(is_sync_stream<next_layer_type>::value,
  883. "SyncStream type requirements not met");
  884. static_assert(net::is_mutable_buffer_sequence<
  885. MutableBufferSequence>::value,
  886. "MutableBufferSequence type requirements not met");
  887. using beast::detail::clamp;
  888. auto& impl = *impl_;
  889. close_code code{};
  890. std::size_t bytes_written = 0;
  891. ec = {};
  892. // Make sure the stream is open
  893. if(impl.check_stop_now(ec))
  894. return bytes_written;
  895. loop:
  896. // See if we need to read a frame header. This
  897. // condition is structured to give the decompressor
  898. // a chance to emit the final empty deflate block
  899. //
  900. if(impl.rd_remain == 0 && (
  901. ! impl.rd_fh.fin || impl.rd_done))
  902. {
  903. // Read frame header
  904. error_code result;
  905. while(! impl.parse_fh(impl.rd_fh, impl.rd_buf, result))
  906. {
  907. if(result)
  908. {
  909. // _Fail the WebSocket Connection_
  910. if(result == error::message_too_big)
  911. code = close_code::too_big;
  912. else
  913. code = close_code::protocol_error;
  914. do_fail(code, result, ec);
  915. return bytes_written;
  916. }
  917. auto const bytes_transferred =
  918. impl.stream().read_some(
  919. impl.rd_buf.prepare(read_size(
  920. impl.rd_buf, impl.rd_buf.max_size())),
  921. ec);
  922. impl.rd_buf.commit(bytes_transferred);
  923. if(impl.check_stop_now(ec))
  924. return bytes_written;
  925. }
  926. // Immediately apply the mask to the portion
  927. // of the buffer holding payload data.
  928. if(impl.rd_fh.len > 0 && impl.rd_fh.mask)
  929. detail::mask_inplace(buffers_prefix(
  930. clamp(impl.rd_fh.len), impl.rd_buf.data()),
  931. impl.rd_key);
  932. if(detail::is_control(impl.rd_fh.op))
  933. {
  934. // Get control frame payload
  935. auto const b = buffers_prefix(
  936. clamp(impl.rd_fh.len), impl.rd_buf.data());
  937. auto const len = buffer_bytes(b);
  938. BOOST_ASSERT(len == impl.rd_fh.len);
  939. // Clear this otherwise the next
  940. // frame will be considered final.
  941. impl.rd_fh.fin = false;
  942. // Handle ping frame
  943. if(impl.rd_fh.op == detail::opcode::ping)
  944. {
  945. ping_data payload;
  946. detail::read_ping(payload, b);
  947. impl.rd_buf.consume(len);
  948. if(impl.wr_close)
  949. {
  950. // Ignore ping when closing
  951. goto loop;
  952. }
  953. if(impl.ctrl_cb)
  954. impl.ctrl_cb(frame_type::ping, payload);
  955. detail::frame_buffer fb;
  956. impl.template write_ping<flat_static_buffer_base>(fb,
  957. detail::opcode::pong, payload);
  958. net::write(impl.stream(), fb.data(), ec);
  959. if(impl.check_stop_now(ec))
  960. return bytes_written;
  961. goto loop;
  962. }
  963. // Handle pong frame
  964. if(impl.rd_fh.op == detail::opcode::pong)
  965. {
  966. ping_data payload;
  967. detail::read_ping(payload, b);
  968. impl.rd_buf.consume(len);
  969. if(impl.ctrl_cb)
  970. impl.ctrl_cb(frame_type::pong, payload);
  971. goto loop;
  972. }
  973. // Handle close frame
  974. BOOST_ASSERT(impl.rd_fh.op == detail::opcode::close);
  975. {
  976. BOOST_ASSERT(! impl.rd_close);
  977. impl.rd_close = true;
  978. close_reason cr;
  979. detail::read_close(cr, b, result);
  980. if(result)
  981. {
  982. // _Fail the WebSocket Connection_
  983. do_fail(close_code::protocol_error,
  984. result, ec);
  985. return bytes_written;
  986. }
  987. impl.cr = cr;
  988. impl.rd_buf.consume(len);
  989. if(impl.ctrl_cb)
  990. impl.ctrl_cb(frame_type::close, impl.cr.reason);
  991. BOOST_ASSERT(! impl.wr_close);
  992. // _Start the WebSocket Closing Handshake_
  993. do_fail(
  994. cr.code == close_code::none ?
  995. close_code::normal :
  996. static_cast<close_code>(cr.code),
  997. error::closed, ec);
  998. return bytes_written;
  999. }
  1000. }
  1001. if(impl.rd_fh.len == 0 && ! impl.rd_fh.fin)
  1002. {
  1003. // Empty non-final frame
  1004. goto loop;
  1005. }
  1006. impl.rd_done = false;
  1007. }
  1008. else
  1009. {
  1010. ec = {};
  1011. }
  1012. if(! impl.rd_deflated())
  1013. {
  1014. if(impl.rd_remain > 0)
  1015. {
  1016. if(impl.rd_buf.size() == 0 && impl.rd_buf.max_size() >
  1017. (std::min)(clamp(impl.rd_remain),
  1018. buffer_bytes(buffers)))
  1019. {
  1020. // Fill the read buffer first, otherwise we
  1021. // get fewer bytes at the cost of one I/O.
  1022. impl.rd_buf.commit(impl.stream().read_some(
  1023. impl.rd_buf.prepare(read_size(impl.rd_buf,
  1024. impl.rd_buf.max_size())), ec));
  1025. if(impl.check_stop_now(ec))
  1026. return bytes_written;
  1027. if(impl.rd_fh.mask)
  1028. detail::mask_inplace(
  1029. buffers_prefix(clamp(impl.rd_remain),
  1030. impl.rd_buf.data()), impl.rd_key);
  1031. }
  1032. if(impl.rd_buf.size() > 0)
  1033. {
  1034. // Copy from the read buffer.
  1035. // The mask was already applied.
  1036. auto const bytes_transferred = net::buffer_copy(
  1037. buffers, impl.rd_buf.data(),
  1038. clamp(impl.rd_remain));
  1039. auto const mb = buffers_prefix(
  1040. bytes_transferred, buffers);
  1041. impl.rd_remain -= bytes_transferred;
  1042. if(impl.rd_op == detail::opcode::text)
  1043. {
  1044. if(! impl.rd_utf8.write(mb) ||
  1045. (impl.rd_remain == 0 && impl.rd_fh.fin &&
  1046. ! impl.rd_utf8.finish()))
  1047. {
  1048. // _Fail the WebSocket Connection_
  1049. do_fail(close_code::bad_payload,
  1050. error::bad_frame_payload, ec);
  1051. return bytes_written;
  1052. }
  1053. }
  1054. bytes_written += bytes_transferred;
  1055. impl.rd_size += bytes_transferred;
  1056. impl.rd_buf.consume(bytes_transferred);
  1057. }
  1058. else
  1059. {
  1060. // Read into caller's buffer
  1061. BOOST_ASSERT(impl.rd_remain > 0);
  1062. BOOST_ASSERT(buffer_bytes(buffers) > 0);
  1063. BOOST_ASSERT(buffer_bytes(buffers_prefix(
  1064. clamp(impl.rd_remain), buffers)) > 0);
  1065. auto const bytes_transferred =
  1066. impl.stream().read_some(buffers_prefix(
  1067. clamp(impl.rd_remain), buffers), ec);
  1068. // VFALCO What if some bytes were written?
  1069. if(impl.check_stop_now(ec))
  1070. return bytes_written;
  1071. BOOST_ASSERT(bytes_transferred > 0);
  1072. auto const mb = buffers_prefix(
  1073. bytes_transferred, buffers);
  1074. impl.rd_remain -= bytes_transferred;
  1075. if(impl.rd_fh.mask)
  1076. detail::mask_inplace(mb, impl.rd_key);
  1077. if(impl.rd_op == detail::opcode::text)
  1078. {
  1079. if(! impl.rd_utf8.write(mb) ||
  1080. (impl.rd_remain == 0 && impl.rd_fh.fin &&
  1081. ! impl.rd_utf8.finish()))
  1082. {
  1083. // _Fail the WebSocket Connection_
  1084. do_fail(close_code::bad_payload,
  1085. error::bad_frame_payload, ec);
  1086. return bytes_written;
  1087. }
  1088. }
  1089. bytes_written += bytes_transferred;
  1090. impl.rd_size += bytes_transferred;
  1091. }
  1092. }
  1093. impl.rd_done = impl.rd_remain == 0 && impl.rd_fh.fin;
  1094. }
  1095. else
  1096. {
  1097. // Read compressed message frame payload:
  1098. // inflate even if rd_fh_.len == 0, otherwise we
  1099. // never emit the end-of-stream deflate block.
  1100. //
  1101. bool did_read = false;
  1102. buffers_suffix<MutableBufferSequence> cb(buffers);
  1103. while(buffer_bytes(cb) > 0)
  1104. {
  1105. zlib::z_params zs;
  1106. {
  1107. auto const out = beast::buffers_front(cb);
  1108. zs.next_out = out.data();
  1109. zs.avail_out = out.size();
  1110. BOOST_ASSERT(zs.avail_out > 0);
  1111. }
  1112. if(impl.rd_remain > 0)
  1113. {
  1114. if(impl.rd_buf.size() > 0)
  1115. {
  1116. // use what's there
  1117. auto const in = buffers_prefix(
  1118. clamp(impl.rd_remain), beast::buffers_front(
  1119. impl.rd_buf.data()));
  1120. zs.avail_in = in.size();
  1121. zs.next_in = in.data();
  1122. }
  1123. else if(! did_read)
  1124. {
  1125. // read new
  1126. auto const bytes_transferred =
  1127. impl.stream().read_some(
  1128. impl.rd_buf.prepare(read_size(
  1129. impl.rd_buf, impl.rd_buf.max_size())),
  1130. ec);
  1131. if(impl.check_stop_now(ec))
  1132. return bytes_written;
  1133. BOOST_ASSERT(bytes_transferred > 0);
  1134. impl.rd_buf.commit(bytes_transferred);
  1135. if(impl.rd_fh.mask)
  1136. detail::mask_inplace(
  1137. buffers_prefix(clamp(impl.rd_remain),
  1138. impl.rd_buf.data()), impl.rd_key);
  1139. auto const in = buffers_prefix(
  1140. clamp(impl.rd_remain), buffers_front(
  1141. impl.rd_buf.data()));
  1142. zs.avail_in = in.size();
  1143. zs.next_in = in.data();
  1144. did_read = true;
  1145. }
  1146. else
  1147. {
  1148. break;
  1149. }
  1150. }
  1151. else if(impl.rd_fh.fin)
  1152. {
  1153. // append the empty block codes
  1154. static std::uint8_t constexpr
  1155. empty_block[4] = {
  1156. 0x00, 0x00, 0xff, 0xff };
  1157. zs.next_in = empty_block;
  1158. zs.avail_in = sizeof(empty_block);
  1159. impl.inflate(zs, zlib::Flush::sync, ec);
  1160. if(! ec)
  1161. {
  1162. // https://github.com/madler/zlib/issues/280
  1163. if(zs.total_out > 0)
  1164. ec = error::partial_deflate_block;
  1165. }
  1166. if(impl.check_stop_now(ec))
  1167. return bytes_written;
  1168. impl.do_context_takeover_read(impl.role);
  1169. impl.rd_done = true;
  1170. break;
  1171. }
  1172. else
  1173. {
  1174. break;
  1175. }
  1176. impl.inflate(zs, zlib::Flush::sync, ec);
  1177. if(impl.check_stop_now(ec))
  1178. return bytes_written;
  1179. if(impl.rd_msg_max && beast::detail::sum_exceeds(
  1180. impl.rd_size, zs.total_out, impl.rd_msg_max))
  1181. {
  1182. do_fail(close_code::too_big,
  1183. error::message_too_big, ec);
  1184. return bytes_written;
  1185. }
  1186. cb.consume(zs.total_out);
  1187. impl.rd_size += zs.total_out;
  1188. impl.rd_remain -= zs.total_in;
  1189. impl.rd_buf.consume(zs.total_in);
  1190. bytes_written += zs.total_out;
  1191. }
  1192. if(impl.rd_op == detail::opcode::text)
  1193. {
  1194. // check utf8
  1195. if(! impl.rd_utf8.write(beast::buffers_prefix(
  1196. bytes_written, buffers)) || (
  1197. impl.rd_done && ! impl.rd_utf8.finish()))
  1198. {
  1199. // _Fail the WebSocket Connection_
  1200. do_fail(close_code::bad_payload,
  1201. error::bad_frame_payload, ec);
  1202. return bytes_written;
  1203. }
  1204. }
  1205. }
  1206. return bytes_written;
  1207. }
  1208. template<class NextLayer, bool deflateSupported>
  1209. template<class MutableBufferSequence, class ReadHandler>
  1210. BOOST_BEAST_ASYNC_RESULT2(ReadHandler)
  1211. stream<NextLayer, deflateSupported>::
  1212. async_read_some(
  1213. MutableBufferSequence const& buffers,
  1214. ReadHandler&& handler)
  1215. {
  1216. static_assert(is_async_stream<next_layer_type>::value,
  1217. "AsyncStream type requirements not met");
  1218. static_assert(net::is_mutable_buffer_sequence<
  1219. MutableBufferSequence>::value,
  1220. "MutableBufferSequence type requirements not met");
  1221. return net::async_initiate<
  1222. ReadHandler,
  1223. void(error_code, std::size_t)>(
  1224. run_read_some_op{},
  1225. handler,
  1226. impl_,
  1227. buffers);
  1228. }
  1229. } // websocket
  1230. } // beast
  1231. } // boost
  1232. #endif