• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <iostream>
25 
26 namespace {
27 
28 #include "websocket_common.ipp"
29 
30 void
snippets()31 snippets()
32 {
33     {
34 
35     stream<tcp_stream> ws(ioc);
36 
37     {
38     //[code_websocket_6_1
39 
40         // Apply suggested timeout options for the server role to the stream
41         ws.set_option(stream_base::timeout::suggested(role_type::server));
42 
43     //]
44     }
45 
46     {
47     //[code_websocket_6_2
48 
49         stream_base::timeout opt{
50             std::chrono::seconds(30),   // handshake timeout
51             stream_base::none(),        // idle timeout
52             false
53         };
54 
55         // Set the timeout options on the stream.
56         ws.set_option(opt);
57 
58     //]
59     }
60 
61     {
62         flat_buffer b;
63     //[code_websocket_6_3
64 
65         ws.async_read(b,
66             [](error_code ec, std::size_t)
67             {
68                 if(ec == beast::error::timeout)
69                     std::cerr << "timeout, connection closed!";
70             });
71     //]
72     }
73 
74     }
75 
76     {
77     //[code_websocket_6_4
78 
79         // Disable any timeouts on the tcp_stream
80         sock.expires_never();
81 
82         // Construct the websocket stream, taking ownership of the existing tcp_stream
83         stream<tcp_stream> ws(std::move(sock));
84 
85     //]
86     }
87 }
88 
89 struct websocket_6_test
90     : public boost::beast::unit_test::suite
91 {
92     void
run__anon7044892b0111::websocket_6_test93     run() override
94     {
95         BEAST_EXPECT(&snippets);
96     }
97 };
98 
99 BEAST_DEFINE_TESTSUITE(beast,doc,websocket_6);
100 
101 } // (anon)
102 
103 #ifdef BOOST_MSVC
104 #pragma warning(pop)
105 #endif
106