Add flat_stream to experimental:

This adds a new stream wrapper class template designed to address
a performance shortcoming of boost::asio::ssl::stream.
This commit is contained in:
Vinnie Falco committed 2018-05-02 08:32:07 -07:00
1 parent 46e658a91b
commit 6108cf3eb7
17 files changed
+801 -850

No files matched your search

+1
View File
@@ -27,6 +27,7 @@ add_executable (tests-beast
)
add_subdirectory (core)
add_subdirectory (experimental)
add_subdirectory (http)
add_subdirectory (websocket)
add_subdirectory (zlib)
+2
View File
@@ -14,6 +14,7 @@ alias run-tests :
[ compile websocket.cpp ]
[ compile zlib.cpp ]
core//run-tests
experimental//run-tests
http//run-tests
websocket//run-tests
zlib//run-tests
@@ -21,6 +22,7 @@ alias run-tests :
alias fat-tests :
core//fat-tests
experimental//fat-tests
http//fat-tests
websocket//fat-tests
zlib//fat-tests
+23
View File
@@ -0,0 +1,23 @@
#
# 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
#
GroupSources(test/extras/include/boost/beast extras)
GroupSources(subtree/unit_test/include/boost/beast extras)
GroupSources(include/boost/beast beast)
GroupSources(test/beast/experimental "/")
add_executable (tests-beast-experimental
${BOOST_BEAST_FILES}
${EXTRAS_FILES}
${TEST_MAIN}
Jamfile
flat_stream.cpp
)
set_property(TARGET tests-beast-experimental PROPERTY FOLDER "tests")
+25
View File
@@ -0,0 +1,25 @@
#
# 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
#
local SOURCES =
flat_stream.cpp
;
local RUN_TESTS ;
for local f in $(SOURCES)
{
RUN_TESTS += [ run $(f) $(TEST_MAIN) ] ;
}
alias run-tests : $(RUN_TESTS) ;
exe fat-tests : $(TEST_MAIN) $(SOURCES) ;
explicit fat-tests ;
+109
View File
@@ -0,0 +1,109 @@
//
// 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/experimental/core/flat_stream.hpp>
#include <boost/beast/test/websocket.hpp>
#include <boost/beast/test/yield_to.hpp>
#include <boost/beast/unit_test/suite.hpp>
#include <initializer_list>
#include <vector>
namespace boost {
namespace beast {
class flat_stream_test
: public unit_test::suite
, public test::enable_yield_to
{
public:
void
testSplit()
{
auto const check =
[&](
std::initializer_list<int> v0,
std::size_t limit,
unsigned long count,
bool copy)
{
std::vector<boost::asio::const_buffer> v;
v.reserve(v0.size());
for(auto const n : v0)
v.emplace_back("", n);
auto const result =
boost::beast::detail::flat_stream_base::coalesce(v, limit);
BEAST_EXPECT(result.first == count);
BEAST_EXPECT(result.second == copy);
return result;
};
check({}, 1, 0, false);
check({1,2}, 1, 1, false);
check({1,2}, 2, 1, false);
check({1,2}, 3, 3, true);
check({1,2}, 4, 3, true);
check({1,2,3}, 1, 1, false);
check({1,2,3}, 2, 1, false);
check({1,2,3}, 3, 3, true);
check({1,2,3}, 4, 3, true);
check({1,2,3}, 7, 6, true);
check({1,2,3,4}, 3, 3, true);
}
void
testHttp()
{
pass();
}
void
testWebsocket()
{
{
error_code ec;
test::ws_echo_server es{log};
boost::asio::io_context ioc;
websocket::stream<flat_stream<test::stream>> ws{ioc};
ws.next_layer().next_layer().connect(es.stream());
ws.handshake("localhost", "/", ec);
BEAST_EXPECTS(! ec, ec.message());
ws.close({}, ec);
BEAST_EXPECTS(! ec, ec.message());
}
{
test::ws_echo_server es{log};
boost::asio::io_context ioc;
websocket::stream<flat_stream<test::stream>> ws{ioc};
ws.next_layer().next_layer().connect(es.stream());
ws.async_handshake("localhost", "/",
[&](error_code)
{
ws.async_close({},
[&](error_code)
{
});
});
ioc.run();
}
}
void
run() override
{
testSplit();
testHttp();
testWebsocket();
}
};
BEAST_DEFINE_TESTSUITE(beast,example,flat_stream);
} // beast
} // boost