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 24 namespace { 25 26 #include "websocket_common.ipp" 27 28 void snippets()29snippets() 30 { 31 { 32 //[code_websocket_1_1 33 34 stream<tcp_stream> ws(ioc); 35 net::ip::tcp::resolver resolver(ioc); 36 37 // Connect the socket to the IP address returned from performing a name lookup 38 get_lowest_layer(ws).connect(resolver.resolve("example.com", "ws")); 39 40 //] 41 } 42 43 { 44 //[code_websocket_1_2 45 46 net::ip::tcp::acceptor acceptor(ioc); 47 acceptor.bind(net::ip::tcp::endpoint(net::ip::tcp::v4(), 0)); 48 acceptor.listen(); 49 50 // The socket returned by accept() will be forwarded to the tcp_stream, 51 // which uses it to perform a move-construction from the net::ip::tcp::socket. 52 53 stream<tcp_stream> ws(acceptor.accept()); 54 55 //] 56 } 57 58 { 59 net::ip::tcp::acceptor acceptor(ioc); 60 //[code_websocket_1_3 61 62 // The stream will use the strand for invoking all completion handlers 63 stream<tcp_stream> ws(net::make_strand(ioc)); 64 65 // This overload of accept uses the socket provided for the new connection. 66 // The function `tcp_stream::socket` provides access to the low-level socket 67 // object contained in the tcp_stream. 68 69 acceptor.accept(get_lowest_layer(ws).socket()); 70 71 //] 72 } 73 } 74 75 struct doc_websocket_1_test 76 : public boost::beast::unit_test::suite 77 { 78 void run__anon5f2c18740111::doc_websocket_1_test79 run() override 80 { 81 BEAST_EXPECT(&snippets); 82 } 83 }; 84 85 BEAST_DEFINE_TESTSUITE(beast,doc,doc_websocket_1); 86 87 } // (anon) 88 89 #ifdef BOOST_MSVC 90 #pragma warning(pop) 91 #endif 92