forked from boostorg/beast
Add websocket::stream timeouts
This commit is contained in:
1 parent
dfd08bf6ae
commit
f21358186e
38 files changed
+3305
-2393
No files matched your search
+112
-17
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (w) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
|
||||
// Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -10,6 +10,8 @@
|
||||
// Test that header file is self-contained.
|
||||
#include <boost/beast/websocket/stream.hpp>
|
||||
|
||||
#include <boost/beast/_experimental/test/stream.hpp>
|
||||
#include <boost/beast/_experimental/test/tcp.hpp>
|
||||
#include "test.hpp"
|
||||
|
||||
#include <boost/asio/io_context.hpp>
|
||||
@@ -168,6 +170,114 @@ public:
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
testTimeout()
|
||||
{
|
||||
using tcp = net::ip::tcp;
|
||||
|
||||
net::io_context ioc;
|
||||
|
||||
// success
|
||||
|
||||
{
|
||||
stream<tcp::socket> ws1(ioc);
|
||||
stream<tcp::socket> ws2(ioc);
|
||||
test::connect(ws1.next_layer(), ws2.next_layer());
|
||||
ws1.async_handshake("test", "/", test::success_handler());
|
||||
ws2.async_accept(test::success_handler());
|
||||
test::run(ioc);
|
||||
|
||||
ws1.async_close({}, test::success_handler());
|
||||
ws2.async_close({}, test::success_handler());
|
||||
test::run(ioc);
|
||||
}
|
||||
|
||||
{
|
||||
stream<test::stream> ws1(ioc);
|
||||
stream<test::stream> ws2(ioc);
|
||||
test::connect(ws1.next_layer(), ws2.next_layer());
|
||||
ws1.async_handshake("test", "/", test::success_handler());
|
||||
ws2.async_accept(test::success_handler());
|
||||
test::run(ioc);
|
||||
|
||||
ws1.async_close({}, test::success_handler());
|
||||
ws2.async_close({}, test::success_handler());
|
||||
test::run(ioc);
|
||||
}
|
||||
|
||||
// success, timeout enabled
|
||||
|
||||
{
|
||||
stream<tcp::socket> ws1(ioc);
|
||||
stream<tcp::socket> ws2(ioc);
|
||||
test::connect(ws1.next_layer(), ws2.next_layer());
|
||||
ws1.async_handshake("test", "/", test::success_handler());
|
||||
ws2.async_accept(test::success_handler());
|
||||
test::run(ioc);
|
||||
|
||||
ws1.set_option(stream_base::timeout{
|
||||
std::chrono::milliseconds(50),
|
||||
stream_base::none(),
|
||||
false});
|
||||
ws1.async_close({}, test::success_handler());
|
||||
ws2.async_close({}, test::success_handler());
|
||||
test::run(ioc);
|
||||
}
|
||||
|
||||
{
|
||||
stream<test::stream> ws1(ioc);
|
||||
stream<test::stream> ws2(ioc);
|
||||
test::connect(ws1.next_layer(), ws2.next_layer());
|
||||
ws1.async_handshake("test", "/", test::success_handler());
|
||||
ws2.async_accept(test::success_handler());
|
||||
test::run(ioc);
|
||||
|
||||
ws1.set_option(stream_base::timeout{
|
||||
std::chrono::milliseconds(50),
|
||||
stream_base::none(),
|
||||
false});
|
||||
ws1.async_close({}, test::success_handler());
|
||||
ws2.async_close({}, test::success_handler());
|
||||
test::run(ioc);
|
||||
}
|
||||
|
||||
// timeout
|
||||
|
||||
{
|
||||
stream<tcp::socket> ws1(ioc);
|
||||
stream<tcp::socket> ws2(ioc);
|
||||
test::connect(ws1.next_layer(), ws2.next_layer());
|
||||
ws1.async_handshake("test", "/", test::success_handler());
|
||||
ws2.async_accept(test::success_handler());
|
||||
test::run(ioc);
|
||||
|
||||
ws1.set_option(stream_base::timeout{
|
||||
std::chrono::milliseconds(50),
|
||||
stream_base::none(),
|
||||
false});
|
||||
ws1.async_close({}, test::fail_handler(
|
||||
beast::error::timeout));
|
||||
test::run(ioc);
|
||||
}
|
||||
|
||||
{
|
||||
stream<test::stream> ws1(ioc);
|
||||
stream<test::stream> ws2(ioc);
|
||||
test::connect(ws1.next_layer(), ws2.next_layer());
|
||||
ws1.async_handshake("test", "/", test::success_handler());
|
||||
ws2.async_accept(test::success_handler());
|
||||
test::run(ioc);
|
||||
|
||||
ws1.set_option(stream_base::timeout{
|
||||
std::chrono::milliseconds(50),
|
||||
stream_base::none(),
|
||||
false});
|
||||
ws1.async_close({}, test::fail_handler(
|
||||
beast::error::timeout));
|
||||
test::run(ioc);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
testSuspend()
|
||||
{
|
||||
@@ -625,28 +735,13 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
testAsioHandlerInvoke()
|
||||
{
|
||||
// make sure things compile, also can set a
|
||||
// breakpoint in asio_handler_invoke to make sure
|
||||
// it is instantiated.
|
||||
net::io_context ioc;
|
||||
net::strand<
|
||||
net::io_context::executor_type> s(
|
||||
ioc.get_executor());
|
||||
stream<test::stream> ws{ioc};
|
||||
ws.async_close({}, net::bind_executor(
|
||||
s, copyable_handler{}));
|
||||
}
|
||||
|
||||
void
|
||||
run() override
|
||||
{
|
||||
testClose();
|
||||
testTimeout();
|
||||
testSuspend();
|
||||
testMoveOnly();
|
||||
testAsioHandlerInvoke();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user