MCPcopy Create free account
hub / github.com/boostorg/beast / testIdlePing

Method testIdlePing

test/beast/websocket/timer.cpp:28–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26 using tcp = boost::asio::ip::tcp;
27
28 void
29 testIdlePing()
30 {
31 net::io_context ioc;
32
33 // idle ping, no timeout
34
35 {
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());
41 test::run(ioc);
42
43 ws2.set_option(stream_base::timeout{
44 stream_base::none(),
45 std::chrono::milliseconds(200),
46 true});
47 flat_buffer b1;
48 flat_buffer b2;
49 bool received = false;
50 ws1.control_callback(
51 [&received](frame_type ft, string_view)
52 {
53 received = true;
54 BEAST_EXPECT(ft == frame_type::ping);
55 });
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);
62 }
63
64 test::run(ioc);
65
66 // idle ping, timeout
67
68 {
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());
74 test::run(ioc);
75
76 ws2.set_option(stream_base::timeout{
77 stream_base::none(),
78 std::chrono::milliseconds(50),
79 true});
80 flat_buffer b;
81 ws2.async_read(b,
82 test::fail_handler(beast::error::timeout));
83 test::run(ioc);
84 }
85

Callers

nothing calls this directly

Calls 9

success_handlerFunction · 0.85
runFunction · 0.85
noneClass · 0.85
fail_handlerFunction · 0.85
run_forFunction · 0.85
set_optionMethod · 0.80
async_readMethod · 0.80
connectFunction · 0.50
async_handshakeMethod · 0.45

Tested by

no test coverage detected