websocket_5_control_frames.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. #include <boost/beast/_experimental/unit_test/suite.hpp>
  10. #ifdef BOOST_MSVC
  11. #pragma warning(push)
  12. #pragma warning(disable: 4459) // declaration hides global declaration
  13. #endif
  14. #include <boost/beast.hpp>
  15. #include <boost/beast/ssl.hpp>
  16. #include <boost/asio.hpp>
  17. #include <boost/asio/ssl.hpp>
  18. namespace {
  19. #include "websocket_common.ipp"
  20. void
  21. snippets()
  22. {
  23. stream<tcp_stream> ws(ioc);
  24. {
  25. //[code_websocket_5_1
  26. ws.control_callback(
  27. [](frame_type kind, string_view payload)
  28. {
  29. // Do something with the payload
  30. boost::ignore_unused(kind, payload);
  31. });
  32. //]
  33. }
  34. {
  35. //[code_websocket_5_2
  36. ws.close(close_code::normal);
  37. //]
  38. }
  39. {
  40. //[code_websocket_5_3
  41. ws.auto_fragment(true);
  42. ws.write_buffer_bytes(16384);
  43. //]
  44. }
  45. }
  46. struct websocket_5_test
  47. : public boost::beast::unit_test::suite
  48. {
  49. void
  50. run() override
  51. {
  52. BEAST_EXPECT(&snippets);
  53. }
  54. };
  55. BEAST_DEFINE_TESTSUITE(beast,doc,websocket_5);
  56. } // (anon)
  57. #ifdef BOOST_MSVC
  58. #pragma warning(pop)
  59. #endif