forked from boostorg/beast
Refactor websocket::stream operations
This commit is contained in:
@@ -21,6 +21,7 @@ add_executable (tests-beast-core
|
||||
stream_tests.hpp
|
||||
test_handler.hpp
|
||||
_detail_base64.cpp
|
||||
_detail_bind_continuation.cpp
|
||||
_detail_buffer.cpp
|
||||
_detail_clamp.cpp
|
||||
_detail_is_invocable.cpp
|
||||
@@ -31,7 +32,6 @@ add_executable (tests-beast-core
|
||||
_detail_varint.cpp
|
||||
async_op_base.cpp
|
||||
basic_stream.cpp
|
||||
bind_continuation.cpp
|
||||
bind_handler.cpp
|
||||
buffer_size.cpp
|
||||
buffer_traits.cpp
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
local SOURCES =
|
||||
_detail_base64.cpp
|
||||
_detail_bind_continuation.cpp
|
||||
_detail_buffer.cpp
|
||||
_detail_clamp.cpp
|
||||
_detail_is_invocable.cpp
|
||||
@@ -19,7 +20,6 @@ local SOURCES =
|
||||
_detail_varint.cpp
|
||||
async_op_base.cpp
|
||||
basic_stream.cpp
|
||||
bind_continuation.cpp
|
||||
bind_handler.cpp
|
||||
buffer_size.cpp
|
||||
buffer_traits.cpp
|
||||
|
||||
+3
-1
@@ -8,7 +8,7 @@
|
||||
//
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include <boost/beast/core/bind_continuation.hpp>
|
||||
#include <boost/beast/core/detail/bind_continuation.hpp>
|
||||
|
||||
#include "test_executor.hpp"
|
||||
#include "test_handler.hpp"
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
namespace boost {
|
||||
namespace beast {
|
||||
namespace detail {
|
||||
|
||||
class bind_continuation_test
|
||||
: public beast::unit_test::suite
|
||||
@@ -182,5 +183,6 @@ public:
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(beast,core,bind_continuation);
|
||||
|
||||
} // detail
|
||||
} // beast
|
||||
} // boost
|
||||
@@ -35,6 +35,7 @@ add_executable (tests-beast-websocket
|
||||
stream_explicit.cpp
|
||||
stream_fwd.cpp
|
||||
teardown.cpp
|
||||
timer.cpp
|
||||
utf8_checker.cpp
|
||||
write.cpp
|
||||
)
|
||||
|
||||
@@ -25,6 +25,7 @@ local SOURCES =
|
||||
stream_explicit.cpp
|
||||
stream_fwd.cpp
|
||||
teardown.cpp
|
||||
timer.cpp
|
||||
utf8_checker.cpp
|
||||
write.cpp
|
||||
;
|
||||
|
||||
@@ -608,21 +608,6 @@ public:
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
testContHook()
|
||||
{
|
||||
struct handler
|
||||
{
|
||||
void operator()(error_code) {}
|
||||
};
|
||||
|
||||
stream<test::stream> ws{ioc_};
|
||||
stream<test::stream>::close_op<handler> op{
|
||||
handler{}, ws, {}};
|
||||
using net::asio_handler_is_continuation;
|
||||
asio_handler_is_continuation(&op);
|
||||
}
|
||||
|
||||
void
|
||||
testMoveOnly()
|
||||
{
|
||||
@@ -660,7 +645,6 @@ public:
|
||||
{
|
||||
testClose();
|
||||
testSuspend();
|
||||
testContHook();
|
||||
testMoveOnly();
|
||||
testAsioHandlerInvoke();
|
||||
}
|
||||
|
||||
@@ -423,21 +423,6 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
testContHook()
|
||||
{
|
||||
struct handler
|
||||
{
|
||||
void operator()(error_code) {}
|
||||
};
|
||||
|
||||
stream<test::stream> ws{ioc_};
|
||||
stream<test::stream>::ping_op<handler> op{
|
||||
handler{}, ws, detail::opcode::ping, {}};
|
||||
using net::asio_handler_is_continuation;
|
||||
asio_handler_is_continuation(&op);
|
||||
}
|
||||
|
||||
void
|
||||
testMoveOnly()
|
||||
{
|
||||
@@ -475,7 +460,6 @@ public:
|
||||
{
|
||||
testPing();
|
||||
testSuspend();
|
||||
testContHook();
|
||||
testMoveOnly();
|
||||
testAsioHandlerInvoke();
|
||||
}
|
||||
|
||||
@@ -339,43 +339,6 @@ public:
|
||||
bad(string_view("\x81\x7f\x00\x00\x00\x00\x00\x00\xff\xff", 10));
|
||||
}
|
||||
|
||||
void
|
||||
testContHook()
|
||||
{
|
||||
{
|
||||
struct handler
|
||||
{
|
||||
void operator()(error_code, std::size_t) {}
|
||||
};
|
||||
|
||||
char buf[32];
|
||||
stream<test::stream> ws{ioc_};
|
||||
stream<test::stream>::read_some_op<
|
||||
net::mutable_buffer,
|
||||
handler> op{handler{}, ws,
|
||||
net::mutable_buffer{
|
||||
buf, sizeof(buf)}};
|
||||
using net::asio_handler_is_continuation;
|
||||
asio_handler_is_continuation(&op);
|
||||
pass();
|
||||
}
|
||||
{
|
||||
struct handler
|
||||
{
|
||||
void operator()(error_code, std::size_t) {}
|
||||
};
|
||||
|
||||
multi_buffer b;
|
||||
stream<test::stream> ws{ioc_};
|
||||
stream<test::stream>::read_op<
|
||||
multi_buffer, handler> op{
|
||||
handler{}, ws, b, 32, true};
|
||||
using net::asio_handler_is_continuation;
|
||||
asio_handler_is_continuation(&op);
|
||||
pass();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
testIssue802()
|
||||
{
|
||||
@@ -675,7 +638,6 @@ public:
|
||||
run() override
|
||||
{
|
||||
testParseFrame();
|
||||
testContHook();
|
||||
testIssue802();
|
||||
testIssue807();
|
||||
testIssue954();
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
|
||||
// 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)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include <boost/beast/websocket/stream.hpp>
|
||||
|
||||
#include <boost/beast/core/flat_buffer.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
|
||||
#include "test.hpp"
|
||||
|
||||
namespace boost {
|
||||
namespace beast {
|
||||
namespace websocket {
|
||||
|
||||
class timer_test
|
||||
: public websocket_test_suite
|
||||
{
|
||||
public:
|
||||
using tcp = boost::asio::ip::tcp;
|
||||
|
||||
static
|
||||
void
|
||||
connect(
|
||||
stream<tcp::socket>& ws1,
|
||||
stream<tcp::socket>& ws2)
|
||||
{
|
||||
struct handler
|
||||
{
|
||||
void
|
||||
operator()(error_code ec)
|
||||
{
|
||||
BEAST_EXPECTS(! ec, ec.message());
|
||||
}
|
||||
};
|
||||
|
||||
tcp::acceptor a(ws1.get_executor().context());
|
||||
auto ep = tcp::endpoint(
|
||||
net::ip::make_address_v4("127.0.0.1"), 0);
|
||||
a.open(ep.protocol());
|
||||
a.set_option(
|
||||
net::socket_base::reuse_address(true));
|
||||
a.bind(ep);
|
||||
a.listen(0);
|
||||
ep = a.local_endpoint();
|
||||
a.async_accept(ws2.next_layer(), handler{});
|
||||
ws1.next_layer().async_connect(ep, handler{});
|
||||
for(;;)
|
||||
{
|
||||
if( ws1.get_executor().context().run_one() +
|
||||
ws2.get_executor().context().run_one() == 0)
|
||||
{
|
||||
ws1.get_executor().context().restart();
|
||||
ws2.get_executor().context().restart();
|
||||
break;
|
||||
}
|
||||
}
|
||||
BEAST_EXPECT(
|
||||
ws1.next_layer().remote_endpoint() ==
|
||||
ws2.next_layer().local_endpoint());
|
||||
BEAST_EXPECT(
|
||||
ws2.next_layer().remote_endpoint() ==
|
||||
ws1.next_layer().local_endpoint());
|
||||
ws2.async_accept(handler{});
|
||||
ws1.async_handshake("test", "/", handler{});
|
||||
for(;;)
|
||||
{
|
||||
if( ws1.get_executor().context().run_one() +
|
||||
ws2.get_executor().context().run_one() == 0)
|
||||
{
|
||||
ws1.get_executor().context().restart();
|
||||
ws2.get_executor().context().restart();
|
||||
break;
|
||||
}
|
||||
}
|
||||
BEAST_EXPECT(ws1.is_open());
|
||||
BEAST_EXPECT(ws2.is_open());
|
||||
BEAST_EXPECT(! ws1.get_executor().context().stopped());
|
||||
BEAST_EXPECT(! ws2.get_executor().context().stopped());
|
||||
}
|
||||
|
||||
#if 0
|
||||
void
|
||||
testRead0()
|
||||
{
|
||||
echo_server es(log, kind::async);
|
||||
|
||||
net::io_context ioc;
|
||||
stream<test::stream> ws(ioc);
|
||||
ws.next_layer().connect(es.stream());
|
||||
|
||||
ws.handshake("localhost", "/");
|
||||
flat_buffer b;
|
||||
ws.async_read(b,
|
||||
[&](error_code ec, std::size_t)
|
||||
{
|
||||
log << ec.message() << "\n";
|
||||
});
|
||||
ioc.run();
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
testRead()
|
||||
{
|
||||
net::io_context ioc;
|
||||
stream<tcp::socket> ws1(ioc);
|
||||
stream<tcp::socket> ws2(ioc);
|
||||
connect(ws1, ws2);
|
||||
flat_buffer b;
|
||||
|
||||
ws2.async_read(b,
|
||||
[&](error_code ec, std::size_t)
|
||||
{
|
||||
log << "ws1.async_read: " << ec.message() << "\n";
|
||||
});
|
||||
ioc.run();
|
||||
}
|
||||
|
||||
void
|
||||
run() override
|
||||
{
|
||||
testRead();
|
||||
pass();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(beast,websocket,timer);
|
||||
|
||||
} // websocket
|
||||
} // beast
|
||||
} // boost
|
||||
@@ -605,25 +605,6 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
testContHook()
|
||||
{
|
||||
struct handler
|
||||
{
|
||||
void operator()(error_code) {}
|
||||
};
|
||||
|
||||
char buf[32];
|
||||
stream<test::stream> ws{ioc_};
|
||||
stream<test::stream>::write_some_op<
|
||||
net::const_buffer,
|
||||
handler> op{handler{}, ws, true,
|
||||
net::const_buffer{
|
||||
buf, sizeof(buf)}};
|
||||
using net::asio_handler_is_continuation;
|
||||
asio_handler_is_continuation(&op);
|
||||
}
|
||||
|
||||
void
|
||||
testMoveOnly()
|
||||
{
|
||||
@@ -669,7 +650,6 @@ public:
|
||||
testWriteSuspend();
|
||||
testAsyncWriteFrame();
|
||||
testIssue300();
|
||||
testContHook();
|
||||
testMoveOnly();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user