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 //[code_websocket_1a 20 21 #include <boost/beast.hpp> 22 #include <boost/beast/ssl.hpp> 23 #include <boost/asio.hpp> 24 #include <boost/asio/ssl.hpp> 25 26 //] 27 28 namespace { 29 30 #include "websocket_common.ipp" 31 32 void snippets()33snippets() 34 { 35 { 36 //[code_websocket_1f 37 38 // This newly constructed WebSocket stream will use the specified 39 // I/O context and have support for the permessage-deflate extension. 40 41 stream<tcp_stream> ws(ioc); 42 43 //] 44 } 45 46 { 47 //[code_websocket_2f 48 49 // The `tcp_stream` will be constructed with a new 50 // strand which uses the specified I/O context. 51 52 stream<tcp_stream> ws(net::make_strand(ioc)); 53 54 //] 55 } 56 57 { 58 //[code_websocket_3f 59 60 // Ownership of the `tcp_stream` is transferred to the websocket stream 61 62 stream<tcp_stream> ws(std::move(sock)); 63 64 //] 65 } 66 67 { 68 stream<tcp_stream> ws(ioc); 69 //[code_websocket_4f 70 71 // Calls `close` on the underlying `beast::tcp_stream` 72 ws.next_layer().close(); 73 74 //] 75 } 76 77 { 78 //[code_websocket_5f 79 80 // The WebSocket stream will use SSL and a new strand 81 stream<ssl_stream<tcp_stream>> wss(net::make_strand(ioc), ctx); 82 83 //] 84 85 //[code_websocket_6f 86 87 // Perform the SSL handshake in the client role 88 wss.next_layer().handshake(net::ssl::stream_base::client); 89 90 //] 91 92 //[code_websocket_7f 93 94 // Cancel all pending I/O on the underlying `tcp_stream` 95 get_lowest_layer(wss).cancel(); 96 97 //] 98 } 99 } 100 101 struct doc_websocket_test 102 : public boost::beast::unit_test::suite 103 { 104 void run__anon78a25a7d0111::doc_websocket_test105 run() override 106 { 107 BEAST_EXPECT(&snippets); 108 } 109 }; 110 111 BEAST_DEFINE_TESTSUITE(beast,doc,doc_websocket); 112 113 } // (anon) 114 115 #ifdef BOOST_MSVC 116 #pragma warning(pop) 117 #endif 118