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
10 #include <boost/config.hpp>
11
12 #ifdef BOOST_MSVC
13 #pragma warning(push)
14 #pragma warning(disable: 4459) // declaration hides global declaration
15 #endif
16
17 #include <boost/beast/_experimental/unit_test/suite.hpp>
18
19 #include <boost/beast.hpp>
20 #include <boost/beast/ssl.hpp>
21 #include <boost/asio.hpp>
22 #include <boost/asio/ssl.hpp>
23 #include <boost/asio/spawn.hpp>
24
25 namespace {
26
27 #include "websocket_common.ipp"
28
29 void
snippets()30 snippets()
31 {
32 stream<tcp_stream> ws(ioc);
33
34 {
35 //[code_websocket_8_1
36
37 flat_buffer buffer;
38
39 ws.async_read(buffer,
40 [](error_code, std::size_t)
41 {
42 // Do something with the buffer
43 });
44
45 //]
46 }
47
48 multi_buffer b;
49
50 {
51 //[code_websocket_8_2
52
53 ws.async_read(b, [](error_code, std::size_t){});
54 ws.async_read(b, [](error_code, std::size_t){});
55
56 //]
57 }
58
59 {
60 //[code_websocket_8_3
61
62 ws.async_read(b, [](error_code, std::size_t){});
63 ws.async_write(b.data(), [](error_code, std::size_t){});
64 ws.async_ping({}, [](error_code){});
65 ws.async_close({}, [](error_code){});
66
67 //]
68 }
69 }
70
71 // workaround for https://github.com/chriskohlhoff/asio/issues/112
72 //#ifdef BOOST_MSVC
73 //[code_websocket_8_1f
74
echo(stream<tcp_stream> & ws,multi_buffer & buffer,net::yield_context yield)75 void echo(stream<tcp_stream>& ws,
76 multi_buffer& buffer, net::yield_context yield)
77 {
78 ws.async_read(buffer, yield);
79 std::future<std::size_t> fut =
80 ws.async_write(buffer.data(), net::use_future);
81 }
82
83 //]
84 //#endif
85
86 struct websocket_8_test
87 : public boost::beast::unit_test::suite
88 {
89 void
run__anonab393bdc0111::websocket_8_test90 run() override
91 {
92 BEAST_EXPECT(&snippets);
93 BEAST_EXPECT(&echo);
94 }
95 };
96
97 BEAST_DEFINE_TESTSUITE(beast,doc,websocket_8);
98
99 } // (anon)
100
101 #ifdef BOOST_MSVC
102 #pragma warning(pop)
103 #endif
104