]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/beast/test/beast/websocket/timer.cpp
2 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
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)
7 // Official repository: https://github.com/boostorg/beast
10 // Test that header file is self-contained.
11 #include <boost/beast/websocket/stream.hpp>
13 #include <boost/beast/_experimental/test/stream.hpp>
14 #include <boost/beast/_experimental/test/tcp.hpp>
15 #include <boost/beast/_experimental/unit_test/suite.hpp>
16 #include <boost/beast/core/flat_buffer.hpp>
17 #include <boost/asio/ip/tcp.hpp>
18 #include <boost/asio/detached.hpp>
24 struct timer_test
: unit_test::suite
26 using tcp
= boost::asio::ip::tcp
;
33 // idle ping, no timeout
36 stream
<tcp::socket
> ws1(ioc
);
37 stream
<tcp::socket
> ws2(ioc
);
38 test::connect(ws1
.next_layer(), ws2
.next_layer());
39 ws1
.async_accept(test::success_handler());
40 ws2
.async_handshake("test", "/", test::success_handler());
43 ws2
.set_option(stream_base::timeout
{
45 std::chrono::milliseconds(100),
49 bool received
= false;
51 [&received
](frame_type ft
, string_view
)
54 BEAST_EXPECT(ft
== frame_type::ping
);
56 ws1
.async_read(b1
, test::fail_handler(
57 net::error::operation_aborted
));
58 ws2
.async_read(b2
, test::fail_handler(
59 net::error::operation_aborted
));
60 test::run_for(ioc
, std::chrono::milliseconds(500));
61 BEAST_EXPECT(received
);
69 stream
<tcp::socket
> ws1(ioc
);
70 stream
<tcp::socket
> ws2(ioc
);
71 test::connect(ws1
.next_layer(), ws2
.next_layer());
72 ws1
.async_accept(test::success_handler());
73 ws2
.async_handshake("test", "/", test::success_handler());
76 ws2
.set_option(stream_base::timeout
{
78 std::chrono::milliseconds(50),
82 test::fail_handler(beast::error::timeout
));
89 // https://github.com/boostorg/beast/issues/1729
95 stream
<tcp::socket
> ws1(ioc
);
96 stream
<tcp::socket
> ws2(ioc
);
97 test::connect(ws1
.next_layer(), ws2
.next_layer());
99 ws1
.set_option(websocket::stream_base::timeout
{
100 std::chrono::milliseconds(50),
101 websocket::stream_base::none(),
104 ws1
.async_accept(net::detached
);
106 "localhost", "/", net::detached
);
113 [&ec2
](error_code ec
)
119 ec2
== beast::error::timeout
||
120 ec2
== net::error::operation_aborted
,
125 stream
<tcp::socket
> ws1(ioc
);
126 stream
<tcp::socket
> ws2(ioc
);
127 test::connect(ws1
.next_layer(), ws2
.next_layer());
129 ws1
.set_option(websocket::stream_base::timeout
{
130 std::chrono::milliseconds(50),
131 websocket::stream_base::none(),
134 ws1
.async_accept(net::detached
);
136 "localhost", "/", net::detached
);
143 [&ec1
](error_code ec
, std::size_t)
148 [&ec2
](error_code ec
)
154 ec1
== beast::error::timeout
||
155 ec2
== beast::error::timeout
);
159 // https://github.com/boostorg/beast/issues/1729#issuecomment-540481056
164 stream
<tcp::socket
> ws1(ioc
);
165 stream
<tcp::socket
> ws2(ioc
);
166 test::connect(ws1
.next_layer(), ws2
.next_layer());
168 ws1
.set_option(websocket::stream_base::timeout
{
169 std::chrono::milliseconds(50),
170 websocket::stream_base::none(),
173 ws1
.async_accept(net::detached
);
175 "localhost", "/", net::detached
);
180 ws1
.async_read(b
, test::fail_handler(
181 beast::error::timeout
));
182 ws1
.async_close({}, test::fail_handler(
183 net::error::operation_aborted
));
192 testCloseWhileRead();
196 BEAST_DEFINE_TESTSUITE(beast
,websocket
,timer
);