Update for Net-TS Asio (API Change):

fix #769

The following classes are removed:

* handler_type
* async_result
* async_completion
* is_dynamic_buffer
* is_const_buffer_sequence
* is_mutable_buffer_sequence
* handler_alloc

Actions Required:

* Use BOOST_ASIO_HANDLER_TYPE instead of handler_type
* Use BOOST_ASIO_INITFN_RESULT_TYPE instead of async_result
* Use boost::asio::async_completion
* Use boost::asio::is_dynamic_buffer
* Use boost::asio::is_const_buffer_sequence
* Use boost::asio::is_mutable_buffer_sequence
* boost::asio::associated_allocator_t replaces handler_alloc
This commit is contained in:
Vinnie Falco committed 2017-10-23 17:11:27 -07:00
1 parent 9dc9ca13b9
commit 3a28e999af
173 files changed
+3214 -4138

No files matched your search

-2
View File
@@ -19,7 +19,6 @@ add_executable (tests-beast-core
Jamfile
buffer_test.hpp
file_test.hpp
async_result.cpp
bind_handler.cpp
buffered_read_stream.cpp
buffers_adapter.cpp
@@ -34,7 +33,6 @@ add_executable (tests-beast-core
file_win32.cpp
flat_buffer.cpp
flat_static_buffer.cpp
handler_alloc.cpp
handler_ptr.cpp
multi_buffer.cpp
ostream.cpp
-2
View File
@@ -8,7 +8,6 @@
#
local SOURCES =
async_result.cpp
bind_handler.cpp
buffered_read_stream.cpp
buffers_adapter.cpp
@@ -23,7 +22,6 @@ local SOURCES =
file_win32.cpp
flat_buffer.cpp
flat_static_buffer.cpp
handler_alloc.cpp
handler_ptr.cpp
multi_buffer.cpp
ostream.cpp
-42
View File
@@ -1,42 +0,0 @@
//
// 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/core/async_result.hpp>
#include <boost/beast/core/error.hpp>
#include <boost/beast/core/type_traits.hpp>
#include <cstdlib>
namespace boost {
namespace beast {
namespace {
struct handler
{
void operator()(beast::error_code, std::size_t) const;
};
static_assert(detail::is_invocable<
typename async_result<handler, void(error_code, std::size_t)>::completion_handler_type,
void(error_code, std::size_t)>::value, "");
static_assert(std::is_same<void,
typename async_result<handler, void(error_code, std::size_t)>::return_type>::value, "");
static_assert(std::is_constructible<
async_result<handler,
void(error_code, std::size_t)>,
typename async_result<handler,
void(error_code, std::size_t)
>::completion_handler_type&>::value, "");
} // (anon-ns)
} // beast
} // boost
+9 -11
View File
@@ -25,17 +25,15 @@ namespace test {
template<class ConstBufferSequence>
typename std::enable_if<
is_const_buffer_sequence<ConstBufferSequence>::value,
boost::asio::is_const_buffer_sequence<ConstBufferSequence>::value,
std::string>::type
to_string(ConstBufferSequence const& bs)
{
using boost::asio::buffer_cast;
using boost::asio::buffer_size;
std::string s;
s.reserve(buffer_size(bs));
for(boost::asio::const_buffer b : bs)
s.append(buffer_cast<char const*>(b),
buffer_size(b));
for(auto b : beast::detail::buffers_range(bs))
s.append(reinterpret_cast<char const*>(b.data()),
b.size());
return s;
}
@@ -50,7 +48,7 @@ write_buffer(DynamicBuffer& b, string_view s)
template<class ConstBufferSequence>
typename std::enable_if<
is_const_buffer_sequence<ConstBufferSequence>::value,
boost::asio::is_const_buffer_sequence<ConstBufferSequence>::value,
std::size_t>::type
buffer_count(ConstBufferSequence const& buffers)
{
@@ -59,7 +57,7 @@ buffer_count(ConstBufferSequence const& buffers)
template<class ConstBufferSequence>
typename std::enable_if<
is_const_buffer_sequence<ConstBufferSequence>::value,
boost::asio::is_const_buffer_sequence<ConstBufferSequence>::value,
std::size_t>::type
size_pre(ConstBufferSequence const& buffers)
{
@@ -78,7 +76,7 @@ size_pre(ConstBufferSequence const& buffers)
template<class ConstBufferSequence>
typename std::enable_if<
is_const_buffer_sequence<ConstBufferSequence>::value,
boost::asio::is_const_buffer_sequence<ConstBufferSequence>::value,
std::size_t>::type
size_post(ConstBufferSequence const& buffers)
{
@@ -90,7 +88,7 @@ size_post(ConstBufferSequence const& buffers)
template<class ConstBufferSequence>
typename std::enable_if<
is_const_buffer_sequence<ConstBufferSequence>::value,
boost::asio::is_const_buffer_sequence<ConstBufferSequence>::value,
std::size_t>::type
size_rev_pre(ConstBufferSequence const& buffers)
{
@@ -102,7 +100,7 @@ size_rev_pre(ConstBufferSequence const& buffers)
template<class ConstBufferSequence>
typename std::enable_if<
is_const_buffer_sequence<ConstBufferSequence>::value,
boost::asio::is_const_buffer_sequence<ConstBufferSequence>::value,
std::size_t>::type
size_rev_post(ConstBufferSequence const& buffers)
{
+16 -15
View File
@@ -31,16 +31,17 @@ class buffered_read_stream_test
public:
void testSpecialMembers()
{
boost::asio::io_service ios;
boost::asio::io_context ioc;
{
buffered_read_stream<test::stream, multi_buffer> srs(ios);
buffered_read_stream<test::stream, multi_buffer> srs(ioc);
buffered_read_stream<test::stream, multi_buffer> srs2(std::move(srs));
srs = std::move(srs2);
BEAST_EXPECT(&srs.get_io_service() == &ios);
BEAST_EXPECT(&srs.get_io_service() == &srs2.get_io_service());
BEAST_EXPECT(&srs.get_executor().context() == &ioc);
BEAST_EXPECT(
&srs.get_executor().context() == &srs2.get_executor().context());
}
{
test::stream ts{ios};
test::stream ts{ioc};
buffered_read_stream<test::stream&, multi_buffer> srs(ts);
}
}
@@ -52,7 +53,7 @@ public:
std::size_t n_ = 0;
std::size_t cap_;
unit_test::suite& suite_;
boost::asio::io_service& ios_;
boost::asio::io_context& ioc_;
boost::optional<test::stream> ts_;
boost::optional<test::fail_counter> fc_;
boost::optional<buffered_read_stream<
@@ -60,11 +61,11 @@ public:
loop(
unit_test::suite& suite,
boost::asio::io_service& ios,
boost::asio::io_context& ioc,
std::size_t cap)
: cap_(cap)
, suite_(suite)
, ios_(ios)
, ioc_(ioc)
{
}
@@ -98,7 +99,7 @@ public:
using boost::asio::buffer_copy;
s_.resize(13);
fc_.emplace(n_);
ts_.emplace(ios_, *fc_, ", world!");
ts_.emplace(ioc_, *fc_, ", world!");
brs_.emplace(*ts_);
brs_->buffer().commit(buffer_copy(
brs_->buffer().prepare(5), buffer("Hello", 5)));
@@ -115,8 +116,8 @@ public:
void
testAsyncLoop()
{
std::make_shared<loop>(*this, ios_, 0)->run();
std::make_shared<loop>(*this, ios_, 3)->run();
std::make_shared<loop>(*this, ioc_, 0)->run();
std::make_shared<loop>(*this, ioc_, 3)->run();
}
void testRead(yield_context do_yield)
@@ -131,7 +132,7 @@ public:
for(n = 0; n < limit; ++n)
{
test::fail_counter fc{n};
test::stream ts(ios_, fc, ", world!");
test::stream ts(ioc_, fc, ", world!");
buffered_read_stream<
test::stream&, multi_buffer> srs(ts);
srs.buffer().commit(buffer_copy(
@@ -149,7 +150,7 @@ public:
for(n = 0; n < limit; ++n)
{
test::fail_counter fc{n};
test::stream ts(ios_, fc, ", world!");
test::stream ts(ioc_, fc, ", world!");
buffered_read_stream<
test::stream&, multi_buffer> srs(ts);
srs.capacity(3);
@@ -168,7 +169,7 @@ public:
for(n = 0; n < limit; ++n)
{
test::fail_counter fc{n};
test::stream ts(ios_, fc, ", world!");
test::stream ts(ioc_, fc, ", world!");
buffered_read_stream<
test::stream&, multi_buffer> srs(ts);
srs.buffer().commit(buffer_copy(
@@ -187,7 +188,7 @@ public:
for(n = 0; n < limit; ++n)
{
test::fail_counter fc{n};
test::stream ts(ios_, fc, ", world!");
test::stream ts(ioc_, fc, ", world!");
buffered_read_stream<
test::stream&, multi_buffer> srs(ts);
srs.capacity(3);
+4 -7
View File
@@ -29,20 +29,17 @@ public:
std::string
to_string(ConstBufferSequence const& bs)
{
using boost::asio::buffer_cast;
using boost::asio::buffer_size;
std::string s;
s.reserve(buffer_size(bs));
for(boost::asio::const_buffer b : bs)
s.append(buffer_cast<char const*>(b),
buffer_size(b));
s.reserve(boost::asio::buffer_size(bs));
for(auto b : beast::detail::buffers_range(bs))
s.append(reinterpret_cast<
char const*>(b.data()), b.size());
return s;
}
void testBuffersAdapter()
{
using boost::asio::buffer;
using boost::asio::buffer_cast;
using boost::asio::buffer_size;
using boost::asio::const_buffer;
using boost::asio::mutable_buffer;
+6 -9
View File
@@ -218,26 +218,23 @@ public:
void run() override
{
using boost::asio::const_buffer;
using boost::asio::const_buffers_1;
using boost::asio::const_buffer;
using boost::asio::mutable_buffer;
using boost::asio::mutable_buffers_1;
struct user_defined : mutable_buffer
{
};
// Check is_all_const_buffer_sequence
BOOST_STATIC_ASSERT(
detail::is_all_const_buffer_sequence<const_buffers_1>::value);
detail::is_all_const_buffer_sequence<const_buffer>::value);
BOOST_STATIC_ASSERT(
detail::is_all_const_buffer_sequence<const_buffers_1, const_buffers_1>::value);
detail::is_all_const_buffer_sequence<const_buffer, const_buffer>::value);
BOOST_STATIC_ASSERT(
detail::is_all_const_buffer_sequence<mutable_buffers_1>::value);
detail::is_all_const_buffer_sequence<mutable_buffer, mutable_buffer>::value);
BOOST_STATIC_ASSERT(
detail::is_all_const_buffer_sequence<mutable_buffers_1, mutable_buffers_1>::value);
detail::is_all_const_buffer_sequence<const_buffer, mutable_buffer>::value);
BOOST_STATIC_ASSERT(
detail::is_all_const_buffer_sequence<const_buffers_1, mutable_buffers_1>::value);
BOOST_STATIC_ASSERT(
! detail::is_all_const_buffer_sequence<const_buffers_1, mutable_buffers_1, int>::value);
! detail::is_all_const_buffer_sequence<const_buffer, mutable_buffer, int>::value);
// Ensure that concatenating mutable buffer
// sequences results in a mutable buffer sequence
+5 -11
View File
@@ -25,18 +25,14 @@ BOOST_STATIC_ASSERT(
std::declval<boost::asio::const_buffer>()))>::value);
BOOST_STATIC_ASSERT(
is_const_buffer_sequence<decltype(
boost::asio::is_const_buffer_sequence<decltype(
buffers_prefix(0,
std::declval<boost::asio::const_buffers_1>()))>::value);
std::declval<boost::asio::const_buffer>()))>::value);
BOOST_STATIC_ASSERT(
std::is_same<boost::asio::mutable_buffer, decltype(
buffers_prefix(0,
std::declval<boost::asio::mutable_buffer>()))>::value);
BOOST_STATIC_ASSERT(
is_mutable_buffer_sequence<decltype(
buffers_prefix(0,
std::declval<boost::asio::mutable_buffers_1>()))>::value);
class buffers_prefix_test : public beast::unit_test::suite
{
@@ -97,13 +93,11 @@ public:
std::string
to_string(ConstBufferSequence const& bs)
{
using boost::asio::buffer_cast;
using boost::asio::buffer_size;
std::string s;
s.reserve(buffer_size(bs));
for(boost::asio::const_buffer b : bs)
s.append(buffer_cast<char const*>(b),
buffer_size(b));
for(auto b : beast::detail::buffers_range(bs))
s.append(reinterpret_cast<char const*>(b.data()),
b.size());
return s;
}
+8 -8
View File
@@ -58,10 +58,10 @@ public:
{
char buf[12];
buffers_suffix<
boost::asio::const_buffers_1> cb1{
boost::asio::const_buffer> cb1{
boost::in_place_init, buf, sizeof(buf)};
buffers_suffix<
boost::asio::const_buffers_1> cb2{
boost::asio::const_buffer> cb2{
boost::in_place_init, nullptr, 0};
cb2 = cb1;
cb1 = std::move(cb2);
@@ -116,11 +116,11 @@ public:
testDefaultCtor()
{
using namespace test;
class test_buffer : public boost::asio::const_buffers_1
class test_buffer : public boost::asio::const_buffer
{
public:
test_buffer()
: boost::asio::const_buffers_1("\r\n", 2)
: boost::asio::const_buffer("\r\n", 2)
{
}
};
@@ -134,11 +134,11 @@ public:
{
using namespace test;
buffers_suffix<buffers_cat_view<
boost::asio::const_buffers_1,
boost::asio::const_buffers_1>> cb(
boost::asio::const_buffer,
boost::asio::const_buffer>> cb(
boost::in_place_init,
boost::asio::const_buffers_1("\r", 1),
boost::asio::const_buffers_1("\n", 1));
boost::asio::const_buffer("\r", 1),
boost::asio::const_buffer("\n", 1));
BEAST_EXPECT(to_string(cb) == "\r\n");
}
+2 -2
View File
@@ -22,8 +22,8 @@
namespace boost {
namespace beast {
static_assert(is_dynamic_buffer<flat_buffer>::value,
"DynamicBuffer requirements not met");
BOOST_STATIC_ASSERT(
boost::asio::is_dynamic_buffer<flat_buffer>::value);
class flat_buffer_test : public beast::unit_test::suite
{
+2 -4
View File
@@ -20,9 +20,8 @@
namespace boost {
namespace beast {
static_assert(
is_dynamic_buffer<flat_static_buffer_base>::value,
"DynamicBuffer requirements not met");
BOOST_STATIC_ASSERT(
boost::asio::is_dynamic_buffer<flat_static_buffer_base>::value);
class flat_static_buffer_test : public beast::unit_test::suite
{
@@ -32,7 +31,6 @@ public:
{
using namespace test;
using boost::asio::buffer;
using boost::asio::buffer_cast;
using boost::asio::buffer_size;
char buf[12];
std::string const s = "Hello, world";
-67
View File
@@ -1,67 +0,0 @@
//
// 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/core/handler_alloc.hpp>
#include <boost/beast/unit_test/suite.hpp>
#include <list>
#include <vector>
namespace boost {
namespace beast {
class handler_alloc_test : public beast::unit_test::suite
{
public:
struct handler
{
void
operator()() const
{
}
};
// https://github.com/boostorg/beast/issues/432
void
testRegression432()
{
handler h;
handler_alloc<int, handler> a{h};
std::list<int, handler_alloc<int, handler>> v{a};
v.push_back(1);
v.push_back(2);
v.push_back(3);
}
void
run() override
{
testRegression432();
handler h;
handler h2;
handler_alloc<char, handler> a1{h};
handler_alloc<char, handler> a2{h2};
BEAST_EXPECT(a2 == a1);
auto a3 = a1;
BEAST_EXPECT(a3 == a1);
{
std::vector<char,
handler_alloc<char, handler>> v(a1);
v.reserve(32);
v.resize(10);
}
}
};
BEAST_DEFINE_TESTSUITE(beast,core,handler_alloc);
} // beast
} // boost
+2 -1
View File
@@ -26,7 +26,8 @@
namespace boost {
namespace beast {
BOOST_STATIC_ASSERT(is_dynamic_buffer<multi_buffer>::value);
BOOST_STATIC_ASSERT(
boost::asio::is_dynamic_buffer<multi_buffer>::value);
class multi_buffer_test : public beast::unit_test::suite
{
+3 -5
View File
@@ -25,13 +25,11 @@ public:
std::string
to_string(ConstBufferSequence const& bs)
{
using boost::asio::buffer_cast;
using boost::asio::buffer_size;
std::string s;
s.reserve(buffer_size(bs));
for(boost::asio::const_buffer b : bs)
s.append(buffer_cast<char const*>(b),
buffer_size(b));
for(auto b : beast::detail::buffers_range(bs))
s.append(reinterpret_cast<
char const*>(b.data()), b.size());
return s;
}
+2 -4
View File
@@ -20,9 +20,8 @@
namespace boost {
namespace beast {
static_assert(
is_dynamic_buffer<static_buffer_base>::value,
"DynamicBuffer requirements not met");
BOOST_STATIC_ASSERT(
boost::asio::is_dynamic_buffer<static_buffer_base>::value);
class static_buffer_test : public beast::unit_test::suite
{
@@ -32,7 +31,6 @@ public:
{
using namespace test;
using boost::asio::buffer;
using boost::asio::buffer_cast;
using boost::asio::buffer_size;
char buf[12];
std::string const s = "Hello, world";
+2 -20
View File
@@ -121,24 +121,6 @@ BOOST_STATIC_ASSERT(min_all(1u, 2u, static_cast<std::uint64_t>(3)) == 1);
} // detail
//
// buffer concepts
//
namespace {
struct T {};
BOOST_STATIC_ASSERT(is_const_buffer_sequence<detail::ConstBufferSequence>::value);
BOOST_STATIC_ASSERT(! is_const_buffer_sequence<T>::value);
BOOST_STATIC_ASSERT(is_mutable_buffer_sequence<detail::MutableBufferSequence>::value);
BOOST_STATIC_ASSERT(! is_mutable_buffer_sequence<T>::value);
BOOST_STATIC_ASSERT(is_dynamic_buffer<boost::asio::streambuf>::value);
} // (anonymous)
//
// handler concepts
//
@@ -169,7 +151,7 @@ struct not_a_stream
get_io_service();
};
BOOST_STATIC_ASSERT(has_get_io_service<stream_type>::value);
BOOST_STATIC_ASSERT(has_get_executor<stream_type>::value);
BOOST_STATIC_ASSERT(is_async_read_stream<stream_type>::value);
BOOST_STATIC_ASSERT(is_async_write_stream<stream_type>::value);
BOOST_STATIC_ASSERT(is_async_stream<stream_type>::value);
@@ -177,7 +159,7 @@ BOOST_STATIC_ASSERT(is_sync_read_stream<stream_type>::value);
BOOST_STATIC_ASSERT(is_sync_write_stream<stream_type>::value);
BOOST_STATIC_ASSERT(is_sync_stream<stream_type>::value);
BOOST_STATIC_ASSERT(! has_get_io_service<not_a_stream>::value);
BOOST_STATIC_ASSERT(! has_get_executor<not_a_stream>::value);
BOOST_STATIC_ASSERT(! is_async_read_stream<not_a_stream>::value);
BOOST_STATIC_ASSERT(! is_async_write_stream<not_a_stream>::value);
BOOST_STATIC_ASSERT(! is_sync_read_stream<not_a_stream>::value);
+10 -10
View File
@@ -152,7 +152,7 @@ public:
template<class Parser, class ConstBufferSequence, class Test>
typename std::enable_if<
is_const_buffer_sequence<ConstBufferSequence>::value>::type
boost::asio::is_const_buffer_sequence<ConstBufferSequence>::value>::type
parsegrind(ConstBufferSequence const& buffers,
Test const& test, bool skip = false)
{
@@ -213,13 +213,13 @@ public:
void
parsegrind(string_view msg, Test const& test, bool skip = false)
{
parsegrind<Parser>(boost::asio::const_buffers_1{
parsegrind<Parser>(boost::asio::const_buffer{
msg.data(), msg.size()}, test, skip);
}
template<class Parser, class ConstBufferSequence>
typename std::enable_if<
is_const_buffer_sequence<ConstBufferSequence>::value>::type
boost::asio::is_const_buffer_sequence<ConstBufferSequence>::value>::type
parsegrind(ConstBufferSequence const& buffers)
{
parsegrind<Parser>(buffers, [](Parser const&){});
@@ -241,7 +241,7 @@ public:
Parser p;
p.eager(true);
error_code ec;
buffers_suffix<boost::asio::const_buffers_1> cb{
buffers_suffix<boost::asio::const_buffer> cb{
boost::in_place_init, msg.data(), msg.size()};
auto n = p.put(buffers_prefix(i, cb), ec);
if(ec == result)
@@ -266,8 +266,8 @@ public:
p.eager(true);
error_code ec;
p.put(buffers_cat(
boost::asio::const_buffers_1{msg.data(), i},
boost::asio::const_buffers_1{
boost::asio::const_buffer{msg.data(), i},
boost::asio::const_buffer{
msg.data() + i, msg.size() - i}), ec);
if(! ec)
p.put_eof(ec);
@@ -887,7 +887,7 @@ public:
//--------------------------------------------------------------------------
static
boost::asio::const_buffers_1
boost::asio::const_buffer
buf(string_view s)
{
return {s.data(), s.size()};
@@ -1140,7 +1140,7 @@ public:
error_code ec;
test_parser<false> p;
p.eager(true);
p.put(boost::asio::const_buffers_1{
p.put(boost::asio::const_buffer{
s.data(), s.size()}, ec);
});
};
@@ -1156,7 +1156,7 @@ public:
error_code ec;
test_parser<false> p;
p.eager(true);
p.put(boost::asio::const_buffers_1{
p.put(boost::asio::const_buffer{
msg.data(), msg.size()}, ec);
BEAST_EXPECTS(! ec, ec.message());
grind(msg);
@@ -1173,7 +1173,7 @@ public:
error_code ec;
test_parser<false> p;
p.eager(true);
p.put(boost::asio::const_buffers_1{
p.put(boost::asio::const_buffer{
msg.data(), msg.size()}, ec);
BEAST_EXPECT(ec);
grind(msg);
+4 -4
View File
@@ -42,10 +42,10 @@ public:
{
std::string s;
s.reserve(boost::asio::buffer_size(buffers));
for(boost::asio::const_buffer buffer : buffers)
for(boost::asio::const_buffer b : beast::detail::buffers_range(buffers))
s.append(
boost::asio::buffer_cast<char const*>(buffer),
boost::asio::buffer_size(buffer));
reinterpret_cast<char const*>(b.data()),
b.size());
return s;
}
@@ -73,7 +73,7 @@ public:
BEAST_EXPECT(to_string(t3) == match);
}
using cb_t = boost::asio::const_buffers_1;
using cb_t = boost::asio::const_buffer;
static
cb_t
+6 -8
View File
@@ -24,7 +24,7 @@ namespace http {
class dynamic_body_test : public beast::unit_test::suite
{
boost::asio::io_service ios_;
boost::asio::io_context ioc_;
public:
template<bool isRequest, class Body, class Fields>
@@ -42,13 +42,11 @@ public:
std::string
to_string(ConstBufferSequence const& bs)
{
using boost::asio::buffer_cast;
using boost::asio::buffer_size;
std::string s;
s.reserve(buffer_size(bs));
for(boost::asio::const_buffer b : bs)
s.append(buffer_cast<char const*>(b),
buffer_size(b));
s.reserve(boost::asio::buffer_size(bs));
for(auto b : beast::detail::buffers_range(bs))
s.append(reinterpret_cast<char const*>(b.data()),
b.size());
return s;
}
@@ -61,7 +59,7 @@ public:
"Content-Length: 3\r\n"
"\r\n"
"xyz";
test::stream ts(ios_, s);
test::stream ts(ioc_, s);
response_parser<dynamic_body> p;
multi_buffer b;
read(ts, b, p);
+4 -3
View File
@@ -10,6 +10,7 @@
// Test that header file is self-contained.
#include <boost/beast/http/file_body.hpp>
#include <boost/beast/core/buffers_prefix.hpp>
#include <boost/beast/core/file_stdio.hpp>
#include <boost/beast/core/flat_buffer.hpp>
#include <boost/beast/http/parser.hpp>
@@ -86,10 +87,10 @@ public:
serializer<false, basic_file_body<File>, fields> sr{res};
sr.next(ec, visit);
BEAST_EXPECTS(! ec, ec.message());
auto const cb = *visit.buffer.data().begin();
auto const b = buffers_front(visit.buffer.data());
string_view const s1{
boost::asio::buffer_cast<char const*>(cb),
boost::asio::buffer_size(cb)};
reinterpret_cast<char const*>(b.data()),
b.size()};
BEAST_EXPECTS(s1 == s, s1);
}
}
+14 -6
View File
@@ -503,10 +503,14 @@ public:
auto const len = rand(500);
ostream(db) <<
"Content-Length: " << len << "\r\n\r\n";
for(boost::asio::mutable_buffer b : db.prepare(len))
auto mb = db.prepare(len);
for(auto it = boost::asio::buffer_sequence_begin(mb);
it != boost::asio::buffer_sequence_end(mb);
++it)
{
auto p = boost::asio::buffer_cast<char*>(b);
auto n = boost::asio::buffer_size(b);
boost::asio::mutable_buffer b = *it;
auto p = reinterpret_cast<char*>(b.data());
auto n = b.size();
while(n--)
*p++ = static_cast<char>(32 + rand(26+26+10+6));
}
@@ -523,10 +527,14 @@ public:
len -= n;
ostream(db) <<
to_hex(n) << "\r\n";
for(boost::asio::mutable_buffer b : db.prepare(n))
auto mb = db.prepare(n);
for(auto it = boost::asio::buffer_sequence_begin(mb);
it != boost::asio::buffer_sequence_end(mb);
++it)
{
auto p = boost::asio::buffer_cast<char*>(b);
auto m = boost::asio::buffer_size(b);
boost::asio::mutable_buffer b = *it;
auto p = reinterpret_cast<char*>(b.data());
auto m = b.size();
while(m--)
*p++ = static_cast<char>(32 + rand(26+26+10+6));
}
+1 -1
View File
@@ -37,7 +37,7 @@ public:
parser<isRequest, string_body>;
static
boost::asio::const_buffers_1
boost::asio::const_buffer
buf(string_view s)
{
return {s.data(), s.size()};
+24 -24
View File
@@ -48,7 +48,7 @@ public:
b.commit(buffer_copy(
b.prepare(len), buffer(s, len)));
test::fail_counter fc(n);
test::stream ts{ios_, fc};
test::stream ts{ioc_, fc};
test_parser<isRequest> p(fc);
error_code ec = test::error::fail_error;
ts.close_remote();
@@ -64,7 +64,7 @@ public:
b.commit(buffer_copy(
b.prepare(pre), buffer(s, pre)));
test::fail_counter fc(n);
test::stream ts{ios_, fc,
test::stream ts{ioc_, fc,
std::string(s + pre, len - pre)};
test_parser<isRequest> p(fc);
error_code ec = test::error::fail_error;
@@ -80,7 +80,7 @@ public:
b.commit(buffer_copy(
b.prepare(len), buffer(s, len)));
test::fail_counter fc(n);
test::stream ts{ios_, fc};
test::stream ts{ioc_, fc};
test_parser<isRequest> p(fc);
error_code ec = test::error::fail_error;
ts.close_remote();
@@ -95,7 +95,7 @@ public:
b.commit(buffer_copy(
b.prepare(len), buffer(s, len)));
test::fail_counter fc(n);
test::stream ts{ios_, fc};
test::stream ts{ioc_, fc};
test_parser<isRequest> p(fc);
error_code ec = test::error::fail_error;
ts.close_remote();
@@ -111,7 +111,7 @@ public:
b.commit(buffer_copy(
b.prepare(pre), buffer(s, pre)));
test::fail_counter fc(n);
test::stream ts(ios_, fc,
test::stream ts(ioc_, fc,
std::string{s + pre, len - pre});
test_parser<isRequest> p(fc);
error_code ec = test::error::fail_error;
@@ -128,7 +128,7 @@ public:
try
{
multi_buffer b;
test::stream c{ios_, "GET / X"};
test::stream c{ioc_, "GET / X"};
c.close_remote();
request_parser<dynamic_body> p;
read(c, b, p);
@@ -144,7 +144,7 @@ public:
testBufferOverflow()
{
{
test::stream c{ios_};
test::stream c{ioc_};
ostream(c.buffer()) <<
"GET / HTTP/1.1\r\n"
"Host: localhost\r\n"
@@ -167,7 +167,7 @@ public:
}
}
{
test::stream c{ios_};
test::stream c{ioc_};
ostream(c.buffer()) <<
"GET / HTTP/1.1\r\n"
"Host: localhost\r\n"
@@ -254,7 +254,7 @@ public:
for(n = 0; n < limit; ++n)
{
test::fail_counter fc{n};
test::stream c{ios_, fc,
test::stream c{ioc_, fc,
"GET / HTTP/1.1\r\n"
"Host: localhost\r\n"
"User-Agent: test\r\n"
@@ -277,7 +277,7 @@ public:
for(n = 0; n < limit; ++n)
{
test::fail_counter fc{n};
test::stream ts{ios_, fc,
test::stream ts{ioc_, fc,
"GET / HTTP/1.1\r\n"
"Host: localhost\r\n"
"User-Agent: test\r\n"
@@ -296,7 +296,7 @@ public:
for(n = 0; n < limit; ++n)
{
test::fail_counter fc{n};
test::stream c{ios_, fc,
test::stream c{ioc_, fc,
"GET / HTTP/1.1\r\n"
"Host: localhost\r\n"
"User-Agent: test\r\n"
@@ -318,7 +318,7 @@ public:
{
{
multi_buffer b;
test::stream ts{ios_};
test::stream ts{ioc_};
request_parser<dynamic_body> p;
error_code ec;
ts.close_remote();
@@ -327,7 +327,7 @@ public:
}
{
multi_buffer b;
test::stream ts{ios_};
test::stream ts{ioc_};
request_parser<dynamic_body> p;
error_code ec;
ts.close_remote();
@@ -352,28 +352,28 @@ public:
{
{
// Make sure handlers are not destroyed
// after calling io_service::stop
boost::asio::io_service ios;
test::stream ts{ios,
// after calling io_context::stop
boost::asio::io_context ioc;
test::stream ts{ioc,
"GET / HTTP/1.1\r\n\r\n"};
BEAST_EXPECT(handler::count() == 0);
multi_buffer b;
request<dynamic_body> m;
async_read(ts, b, m, handler{});
BEAST_EXPECT(handler::count() > 0);
ios.stop();
ioc.stop();
BEAST_EXPECT(handler::count() > 0);
ios.reset();
ioc.restart();
BEAST_EXPECT(handler::count() > 0);
ios.run_one();
ioc.run_one();
BEAST_EXPECT(handler::count() == 0);
}
{
// Make sure uninvoked handlers are
// destroyed when calling ~io_service
// destroyed when calling ~io_context
{
boost::asio::io_service ios;
test::stream ts{ios,
boost::asio::io_context ioc;
test::stream ts{ioc,
"GET / HTTP/1.1\r\n\r\n"};
BEAST_EXPECT(handler::count() == 0);
multi_buffer b;
@@ -389,7 +389,7 @@ public:
void
testRegression430()
{
test::stream ts{ios_};
test::stream ts{ioc_};
ts.read_size(1);
ostream(ts.buffer()) <<
"HTTP/1.1 200 OK\r\n"
@@ -417,7 +417,7 @@ public:
Parser p;
error_code ec = test::error::fail_error;
flat_buffer b;
test::stream ts{ios_};
test::stream ts{ioc_};
ostream(ts.buffer()) << s;
ts.read_size(n);
read(ts, b, p, ec);
+2 -2
View File
@@ -27,7 +27,7 @@ public:
struct reader
{
using const_buffers_type =
boost::asio::const_buffers_1;
boost::asio::const_buffer;
template<bool isRequest, class Fields>
reader(message<isRequest, const_body, Fields> const&);
@@ -47,7 +47,7 @@ public:
struct reader
{
using const_buffers_type =
boost::asio::const_buffers_1;
boost::asio::const_buffer;
template<bool isRequest, class Fields>
reader(message<isRequest, mutable_body, Fields>&);
+2 -2
View File
@@ -54,13 +54,13 @@ struct span_body_test
error_code ec;
w.init(boost::none, ec);
BEAST_EXPECTS(! ec, ec.message());
w.put(boost::asio::const_buffers_1{
w.put(boost::asio::const_buffer{
"123", 3}, ec);
BEAST_EXPECTS(! ec, ec.message());
BEAST_EXPECT(buf[0] == '1');
BEAST_EXPECT(buf[1] == '2');
BEAST_EXPECT(buf[2] == '3');
w.put(boost::asio::const_buffers_1{
w.put(boost::asio::const_buffer{
"456", 3}, ec);
BEAST_EXPECTS(ec == error::buffer_overflow, ec.message());
}
+1 -1
View File
@@ -27,7 +27,7 @@ class test_parser
public:
using mutable_buffers_type =
boost::asio::mutable_buffers_1;
boost::asio::mutable_buffer;
int status = 0;
int version = 0;
+30 -32
View File
@@ -44,7 +44,7 @@ public:
public:
using const_buffers_type =
boost::asio::const_buffers_1;
boost::asio::const_buffer;
template<bool isRequest, class Allocator>
explicit
@@ -89,7 +89,7 @@ public:
public:
using const_buffers_type =
boost::asio::const_buffers_1;
boost::asio::const_buffer;
template<bool isRequest, class Fields>
explicit
@@ -226,7 +226,7 @@ public:
public:
using const_buffers_type =
boost::asio::const_buffers_1;
boost::asio::const_buffer;
template<bool isRequest, class Allocator>
explicit
@@ -270,13 +270,11 @@ public:
std::string
to_string(ConstBufferSequence const& bs)
{
using boost::asio::buffer_cast;
using boost::asio::buffer_size;
std::string s;
s.reserve(buffer_size(bs));
for(boost::asio::const_buffer b : bs)
s.append(buffer_cast<char const*>(b),
buffer_size(b));
for(auto b : beast::detail::buffers_range(bs))
s.append(reinterpret_cast<char const*>(b),
b.size());
return s;
}
@@ -284,7 +282,7 @@ public:
bool
equal_body(string_view sv, string_view body)
{
test::stream ts{ios_, sv}, tr{ios_};
test::stream ts{ioc_, sv}, tr{ioc_};
ts.connect(tr);
message<isRequest, string_body, fields> m;
multi_buffer b;
@@ -305,7 +303,7 @@ public:
std::string
str(message<isRequest, Body, Fields> const& m)
{
test::stream ts{ios_}, tr{ios_};
test::stream ts{ioc_}, tr{ioc_};
ts.connect(tr);
error_code ec;
write(ts, m, ec);
@@ -325,7 +323,7 @@ public:
m.set(field::content_length, "5");
m.body() = "*****";
error_code ec;
test::stream ts{ios_}, tr{ios_};
test::stream ts{ioc_}, tr{ioc_};
ts.connect(tr);
async_write(ts, m, do_yield[ec]);
BEAST_EXPECT(! m.keep_alive());
@@ -345,7 +343,7 @@ public:
m.set(field::transfer_encoding, "chunked");
m.body() = "*****";
error_code ec;
test::stream ts{ios_}, tr{ios_};
test::stream ts{ioc_}, tr{ioc_};
ts.connect(tr);
async_write(ts, m, do_yield[ec]);
if(BEAST_EXPECTS(! ec, ec.message()))
@@ -369,7 +367,7 @@ public:
for(n = 0; n < limit; ++n)
{
test::fail_counter fc(n);
test::stream ts{ios_, fc}, tr{ios_};
test::stream ts{ioc_, fc}, tr{ioc_};
ts.connect(tr);
request<fail_body> m(verb::get, "/", 10, fc);
m.set(field::user_agent, "test");
@@ -399,7 +397,7 @@ public:
for(n = 0; n < limit; ++n)
{
test::fail_counter fc(n);
test::stream ts{ios_, fc}, tr{ios_};
test::stream ts{ioc_, fc}, tr{ioc_};
ts.connect(tr);
request<fail_body> m{verb::get, "/", 10, fc};
m.set(field::user_agent, "test");
@@ -430,7 +428,7 @@ public:
for(n = 0; n < limit; ++n)
{
test::fail_counter fc(n);
test::stream ts{ios_, fc}, tr{ios_};
test::stream ts{ioc_, fc}, tr{ioc_};
ts.connect(tr);
request<fail_body> m{verb::get, "/", 10, fc};
m.set(field::user_agent, "test");
@@ -461,7 +459,7 @@ public:
for(n = 0; n < limit; ++n)
{
test::fail_counter fc(n);
test::stream ts{ios_, fc}, tr{ios_};
test::stream ts{ioc_, fc}, tr{ioc_};
ts.connect(tr);
request<fail_body> m{verb::get, "/", 10, fc};
m.set(field::user_agent, "test");
@@ -488,7 +486,7 @@ public:
for(n = 0; n < limit; ++n)
{
test::fail_counter fc(n);
test::stream ts{ios_, fc}, tr{ios_};
test::stream ts{ioc_, fc}, tr{ioc_};
ts.connect(tr);
request<fail_body> m{verb::get, "/", 10, fc};
m.set(field::user_agent, "test");
@@ -542,7 +540,7 @@ public:
m.set(field::user_agent, "test");
m.body() = "*";
m.prepare_payload();
test::stream ts{ios_}, tr{ios_};
test::stream ts{ioc_}, tr{ioc_};
ts.connect(tr);
error_code ec;
write(ts, m, ec);
@@ -581,7 +579,7 @@ public:
m.set(field::user_agent, "test");
m.body() = "*";
m.prepare_payload();
test::stream ts{ios_}, tr{ios_};
test::stream ts{ioc_}, tr{ioc_};
ts.connect(tr);
error_code ec;
write(ts, m, ec);
@@ -648,9 +646,9 @@ public:
{
{
// Make sure handlers are not destroyed
// after calling io_service::stop
boost::asio::io_service ios;
test::stream ts{ios};
// after calling io_context::stop
boost::asio::io_context ioc;
test::stream ts{ioc};
BEAST_EXPECT(handler::count() == 0);
request<string_body> m;
m.method(verb::get);
@@ -660,19 +658,19 @@ public:
m.body() = "*****";
async_write(ts, m, handler{});
BEAST_EXPECT(handler::count() > 0);
ios.stop();
ioc.stop();
BEAST_EXPECT(handler::count() > 0);
ios.reset();
ioc.restart();
BEAST_EXPECT(handler::count() > 0);
ios.run_one();
ioc.run_one();
BEAST_EXPECT(handler::count() == 0);
}
{
// Make sure uninvoked handlers are
// destroyed when calling ~io_service
// destroyed when calling ~io_context
{
boost::asio::io_service ios;
test::stream ts{ios}, tr{ios};
boost::asio::io_context ioc;
test::stream ts{ioc}, tr{ioc};
ts.connect(tr);
BEAST_EXPECT(handler::count() == 0);
request<string_body> m;
@@ -733,7 +731,7 @@ public:
void
testWriteStream(boost::asio::yield_context yield)
{
test::stream ts{ios_}, tr{ios_};
test::stream ts{ioc_}, tr{ioc_};
ts.connect(tr);
ts.write_size(3);
@@ -849,8 +847,8 @@ public:
void
testIssue655()
{
boost::asio::io_service ios;
test::stream ts{ios}, tr{ios};
boost::asio::io_context ioc;
test::stream ts{ioc}, tr{ioc};
ts.connect(tr);
response<empty_body> res;
res.chunked(true);
@@ -859,7 +857,7 @@ public:
[&](error_code const&, std::size_t)
{
});
ios.run();
ioc.run();
}
void
+8 -8
View File
@@ -70,7 +70,7 @@ public:
// request in stream, oversized
{
stream<test::stream> ws{ios_,
stream<test::stream> ws{ioc_,
"GET / HTTP/1.1\r\n"
"Host: localhost\r\n"
"Upgrade: websocket\r\n"
@@ -115,7 +115,7 @@ public:
// request in stream, decorator, oversized
{
stream<test::stream> ws{ios_,
stream<test::stream> ws{ioc_,
"GET / HTTP/1.1\r\n"
"Host: localhost\r\n"
"Upgrade: websocket\r\n"
@@ -158,7 +158,7 @@ public:
// request in buffers, oversize
{
stream<test::stream> ws{ios_};
stream<test::stream> ws{ioc_};
auto tr = connect(ws.next_layer());
try
{
@@ -202,7 +202,7 @@ public:
// request in buffers, decorator, oversized
{
stream<test::stream> ws{ios_};
stream<test::stream> ws{ioc_};
auto tr = connect(ws.next_layer());
try
{
@@ -248,7 +248,7 @@ public:
// request in buffers and stream, oversized
{
stream<test::stream> ws{ios_,
stream<test::stream> ws{ioc_,
"Connection: upgrade\r\n"
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"
"Sec-WebSocket-Version: 13\r\n"
@@ -294,7 +294,7 @@ public:
// request in buffers and stream, decorator, oversize
{
stream<test::stream> ws{ios_,
stream<test::stream> ws{ioc_,
"Connection: upgrade\r\n"
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"
"Sec-WebSocket-Version: 13\r\n"
@@ -415,7 +415,7 @@ public:
// Closed by client
{
stream<test::stream> ws{ios_};
stream<test::stream> ws{ioc_};
auto tr = connect(ws.next_layer());
tr.close();
try
@@ -466,7 +466,7 @@ public:
n = s.size() - 1;
break;
}
stream<test::stream> ws{ios_};
stream<test::stream> ws{ioc_};
auto tr = connect(ws.next_layer());
ws.next_layer().append(
s.substr(n, s.size() - n));
+41 -41
View File
@@ -50,7 +50,7 @@ public:
// already closed
{
echo_server es{log};
stream<test::stream> ws{ios_};
stream<test::stream> ws{ioc_};
ws.next_layer().connect(es.stream());
w.handshake(ws, "localhost", "/");
w.close(ws, {});
@@ -96,7 +96,7 @@ public:
// drain invalid message frame after close
{
echo_server es{log};
stream<test::stream> ws{ios_};
stream<test::stream> ws{ioc_};
ws.next_layer().connect(es.stream());
w.handshake(ws, "localhost", "/");
ws.next_layer().append("\x81\x81\xff\xff\xff\xff*");
@@ -116,7 +116,7 @@ public:
// drain invalid close frame after close
{
echo_server es{log};
stream<test::stream> ws{ios_};
stream<test::stream> ws{ioc_};
ws.next_layer().connect(es.stream());
w.handshake(ws, "localhost", "/");
ws.next_layer().append("\x88\x01*");
@@ -136,7 +136,7 @@ public:
// drain masked close frame
{
echo_server es{log, kind::async_client};
stream<test::stream> ws{ios_};
stream<test::stream> ws{ioc_};
ws.next_layer().connect(es.stream());
ws.set_option(pmd);
es.async_handshake();
@@ -174,8 +174,8 @@ public:
doFailLoop([&](test::fail_counter& fc)
{
echo_server es{log};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
std::size_t count = 0;
@@ -198,7 +198,7 @@ public:
system_error{ec});
});
BEAST_EXPECT(count == 0);
ios.run();
ioc.run();
BEAST_EXPECT(count == 2);
});
@@ -206,8 +206,8 @@ public:
doFailLoop([&](test::fail_counter& fc)
{
echo_server es{log};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
std::size_t count = 0;
@@ -231,7 +231,7 @@ public:
system_error{ec});
});
BEAST_EXPECT(count == 0);
ios.run();
ioc.run();
BEAST_EXPECT(count == 2);
});
@@ -239,8 +239,8 @@ public:
doFailLoop([&](test::fail_counter& fc)
{
echo_server es{log};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
// add a ping and message to the input
@@ -258,8 +258,8 @@ public:
});
while(! ws.wr_block_)
{
ios.run_one();
if(! BEAST_EXPECT(! ios.stopped()))
ioc.run_one();
if(! BEAST_EXPECT(! ioc.stopped()))
break;
}
BEAST_EXPECT(count == 0);
@@ -272,7 +272,7 @@ public:
system_error{ec});
});
BEAST_EXPECT(count == 0);
ios.run();
ioc.run();
BEAST_EXPECT(count == 2);
});
@@ -280,8 +280,8 @@ public:
doFailLoop([&](test::fail_counter& fc)
{
echo_server es{log};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
// add an invalid frame to the input
@@ -299,8 +299,8 @@ public:
});
while(! ws.wr_block_)
{
ios.run_one();
if(! BEAST_EXPECT(! ios.stopped()))
ioc.run_one();
if(! BEAST_EXPECT(! ioc.stopped()))
break;
}
BEAST_EXPECT(count == 0);
@@ -313,7 +313,7 @@ public:
BEAST_EXPECT(++count == 2);
});
BEAST_EXPECT(count == 0);
ios.run();
ioc.run();
BEAST_EXPECT(count == 2);
});
@@ -321,8 +321,8 @@ public:
doFailLoop([&](test::fail_counter& fc)
{
echo_server es{log};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
// add a close frame to the input
@@ -340,8 +340,8 @@ public:
});
while(! ws.wr_block_)
{
ios.run_one();
if(! BEAST_EXPECT(! ios.stopped()))
ioc.run_one();
if(! BEAST_EXPECT(! ioc.stopped()))
break;
}
BEAST_EXPECT(count == 0);
@@ -354,7 +354,7 @@ public:
BEAST_EXPECT(++count == 2);
});
BEAST_EXPECT(count == 0);
ios.run();
ioc.run();
BEAST_EXPECT(count == 2);
});
@@ -362,8 +362,8 @@ public:
doFailLoop([&](test::fail_counter& fc)
{
echo_server es{log};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
// add a close frame to the input
@@ -398,7 +398,7 @@ public:
BEAST_EXPECT(++count == 2);
});
BEAST_EXPECT(count == 0);
ios.run();
ioc.run();
BEAST_EXPECT(count == 3);
});
@@ -406,8 +406,8 @@ public:
doFailLoop([&](test::fail_counter& fc)
{
echo_server es{log};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
// add a ping frame to the input
@@ -445,7 +445,7 @@ public:
BEAST_EXPECT(ws.is_open());
BEAST_EXPECT(ws.wr_block_);
BEAST_EXPECT(count == 0);
ios.run();
ioc.run();
BEAST_EXPECT(count == 3);
});
@@ -453,8 +453,8 @@ public:
doFailLoop([&](test::fail_counter& fc)
{
echo_server es{log};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
std::size_t count = 0;
@@ -493,7 +493,7 @@ public:
++count;
});
BEAST_EXPECT(count == 0);
ios.run();
ioc.run();
BEAST_EXPECT(count == 4);
});
@@ -501,8 +501,8 @@ public:
doFailLoop([&](test::fail_counter& fc)
{
echo_server es{log};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
std::size_t count = 0;
@@ -554,7 +554,7 @@ public:
BEAST_EXPECT(count == 2 || count == 3);
});
BEAST_EXPECT(count == 0);
ios.run();
ioc.run();
BEAST_EXPECT(count == 4);
});
@@ -562,8 +562,8 @@ public:
doFailLoop([&](test::fail_counter& fc)
{
echo_server es{log};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
std::size_t count = 0;
@@ -602,7 +602,7 @@ public:
BEAST_EXPECT(++count == 2);
});
BEAST_EXPECT(count == 0);
ios.run();
ioc.run();
BEAST_EXPECT(count == 4);
});
}
@@ -615,7 +615,7 @@ public:
void operator()(error_code) {}
};
stream<test::stream> ws{ios_};
stream<test::stream> ws{ioc_};
stream<test::stream>::close_op<handler> op{
handler{}, ws, {}};
using boost::asio::asio_handler_is_continuation;
+1 -1
View File
@@ -139,7 +139,7 @@ public:
auto const check =
[&](std::string const& s)
{
stream<test::stream> ws{ios_};
stream<test::stream> ws{ioc_};
auto tr = connect(ws.next_layer());
ws.next_layer().append(s);
tr.close();
+37 -37
View File
@@ -42,7 +42,7 @@ public:
// ping, already closed
{
echo_server es{log};
stream<test::stream> ws{ios_};
stream<test::stream> ws{ioc_};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
ws.close({});
@@ -62,7 +62,7 @@ public:
// pong, already closed
{
echo_server es{log};
stream<test::stream> ws{ios_};
stream<test::stream> ws{ioc_};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
ws.close({});
@@ -98,8 +98,8 @@ public:
doFailLoop([&](test::fail_counter& fc)
{
echo_server es{log};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
std::size_t count = 0;
@@ -123,7 +123,7 @@ public:
system_error{ec});
});
BEAST_EXPECT(count == 0);
ios.run();
ioc.run();
BEAST_EXPECT(count == 2);
});
@@ -131,8 +131,8 @@ public:
doFailLoop([&](test::fail_counter& fc)
{
echo_server es{log};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
std::size_t count = 0;
@@ -155,7 +155,7 @@ public:
system_error{ec});
});
BEAST_EXPECT(count == 0);
ios.run();
ioc.run();
BEAST_EXPECT(count == 2);
});
@@ -163,8 +163,8 @@ public:
doFailLoop([&](test::fail_counter& fc)
{
echo_server es{log};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
// add a ping and message to the input
@@ -182,8 +182,8 @@ public:
});
while(! ws.wr_block_)
{
ios.run_one();
if(! BEAST_EXPECT(! ios.stopped()))
ioc.run_one();
if(! BEAST_EXPECT(! ioc.stopped()))
break;
}
BEAST_EXPECT(count == 0);
@@ -196,7 +196,7 @@ public:
system_error{ec});
});
BEAST_EXPECT(count == 0);
ios.run();
ioc.run();
BEAST_EXPECT(count == 2);
});
@@ -204,8 +204,8 @@ public:
doFailLoop([&](test::fail_counter& fc)
{
echo_server es{log};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
// add an invalid frame to the input
@@ -224,8 +224,8 @@ public:
});
while(! ws.wr_block_)
{
ios.run_one();
if(! BEAST_EXPECT(! ios.stopped()))
ioc.run_one();
if(! BEAST_EXPECT(! ioc.stopped()))
break;
}
BEAST_EXPECT(count == 0);
@@ -238,7 +238,7 @@ public:
system_error{ec});
});
BEAST_EXPECT(count == 0);
ios.run();
ioc.run();
BEAST_EXPECT(count == 2);
});
@@ -246,8 +246,8 @@ public:
doFailLoop([&](test::fail_counter& fc)
{
echo_server es{log};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
// add a close frame to the input
@@ -265,8 +265,8 @@ public:
});
while(! ws.wr_block_)
{
ios.run_one();
if(! BEAST_EXPECT(! ios.stopped()))
ioc.run_one();
if(! BEAST_EXPECT(! ioc.stopped()))
break;
}
BEAST_EXPECT(count == 0);
@@ -279,7 +279,7 @@ public:
system_error{ec});
});
BEAST_EXPECT(count == 0);
ios.run();
ioc.run();
BEAST_EXPECT(count == 2);
});
@@ -287,8 +287,8 @@ public:
doFailLoop([&](test::fail_counter& fc)
{
echo_server es{log, kind::async};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
// Cause close to be received
@@ -305,8 +305,8 @@ public:
});
while(! ws.wr_block_)
{
ios.run_one();
if(! BEAST_EXPECT(! ios.stopped()))
ioc.run_one();
if(! BEAST_EXPECT(! ioc.stopped()))
break;
}
BEAST_EXPECT(count == 0);
@@ -319,7 +319,7 @@ public:
system_error{ec});
});
BEAST_EXPECT(count == 0);
ios.run();
ioc.run();
BEAST_EXPECT(count == 2);
});
@@ -328,8 +328,8 @@ public:
{
echo_server es{log};
error_code ec;
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
std::size_t count = 0;
@@ -359,14 +359,14 @@ public:
BOOST_THROW_EXCEPTION(
system_error{ec});
});
ios.run();
ioc.run();
BEAST_EXPECT(count == 3);
});
{
echo_server es{log, kind::async};
boost::asio::io_service ios;
stream<test::stream> ws{ios};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
@@ -394,7 +394,7 @@ public:
ec.message());
});
});
if(! BEAST_EXPECT(run_until(ios, 100,
if(! BEAST_EXPECT(run_until(ioc, 100,
[&]{ return ws.wr_close_; })))
return;
// Try to ping
@@ -422,10 +422,10 @@ public:
{
if(count >= 4)
break;
ios.run_one();
ioc.run_one();
}
BEAST_EXPECT(n < limit);
ios.run();
ioc.run();
}
}
@@ -437,7 +437,7 @@ public:
void operator()(error_code) {}
};
stream<test::stream> ws{ios_};
stream<test::stream> ws{ioc_};
stream<test::stream>::ping_op<handler> op{
handler{}, ws, detail::opcode::ping, {}};
using boost::asio::asio_handler_is_continuation;
+44 -44
View File
@@ -76,7 +76,7 @@ public:
// already closed
{
echo_server es{log};
stream<test::stream> ws{ios_};
stream<test::stream> ws{ioc_};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
ws.close({});
@@ -236,8 +236,8 @@ public:
doFailLoop([&](test::fail_counter& fc)
{
echo_server es{log, kind::async};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
// Cause close to be received
@@ -252,7 +252,7 @@ public:
BOOST_THROW_EXCEPTION(
system_error{ec});
});
ios.run();
ioc.run();
BEAST_EXPECT(count == 1);
});
@@ -375,7 +375,7 @@ public:
[&](error_code ev, string_view s)
{
echo_server es{log};
stream<test::stream> ws{ios_};
stream<test::stream> ws{ioc_};
ws.next_layer().connect(es.stream());
w.handshake(ws, "localhost", "/");
ws.next_layer().append(s);
@@ -619,7 +619,7 @@ public:
[&](error_code ev, string_view s)
{
echo_server es{log};
stream<test::stream> ws{ios_};
stream<test::stream> ws{ioc_};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
ws.next_layer().append(s);
@@ -657,8 +657,8 @@ public:
doFailLoop([&](test::fail_counter& fc)
{
echo_server es{log};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
std::size_t count = 0;
@@ -671,7 +671,7 @@ public:
BEAST_EXPECT(++count == 1);
});
while(! ws.rd_block_)
ios.run_one();
ioc.run_one();
multi_buffer b;
ws.async_read(b,
[&](error_code ec, std::size_t)
@@ -681,7 +681,7 @@ public:
system_error{ec});
BEAST_EXPECT(++count == 2);
});
ios.run();
ioc.run();
BEAST_EXPECT(count == 2);
});
#endif
@@ -691,8 +691,8 @@ public:
{
//log << "fc.count()==" << fc.count() << std::endl;
echo_server es{log};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
std::size_t count = 0;
@@ -714,7 +714,7 @@ public:
system_error{ec});
BEAST_EXPECT(++count == 1);
});
ios.run();
ioc.run();
BEAST_EXPECT(count == 2);
});
@@ -723,8 +723,8 @@ public:
doFailLoop([&](test::fail_counter& fc)
{
echo_server es{log};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
// insert a ping
@@ -753,7 +753,7 @@ public:
++count;
});
BEAST_EXPECT(ws.wr_block_);
ios.run();
ioc.run();
BEAST_EXPECT(count == 2);
});
@@ -761,8 +761,8 @@ public:
doFailLoop([&](test::fail_counter& fc)
{
echo_server es{log};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
std::size_t count = 0;
@@ -801,7 +801,7 @@ public:
BEAST_EXPECT(++count == 2);
});
BEAST_EXPECT(ws.wr_block_);
ios.run();
ioc.run();
BEAST_EXPECT(count == 3);
});
@@ -809,8 +809,8 @@ public:
doFailLoop([&](test::fail_counter& fc)
{
echo_server es{log};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
std::size_t count = 0;
@@ -839,7 +839,7 @@ public:
BEAST_EXPECT(++count == 1);
});
BEAST_EXPECT(ws.wr_block_);
ios.run();
ioc.run();
BEAST_EXPECT(count == 2);
});
#endif
@@ -852,8 +852,8 @@ public:
[&](string_view s)
{
echo_server es{log};
boost::asio::io_service ios;
stream<test::stream> ws{ios};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
ws.next_layer().append(s);
@@ -866,8 +866,8 @@ public:
// chopped frame header
{
echo_server es{log};
boost::asio::io_service ios;
stream<test::stream> ws{ios};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
ws.next_layer().append(
@@ -883,10 +883,10 @@ public:
BEAST_EXPECTS(! ec, ec.message());
BEAST_EXPECT(to_string(b.data()) == s);
});
ios.run_one();
ioc.run_one();
es.stream().write_some(
boost::asio::buffer("\x01" + s));
ios.run();
ioc.run();
BEAST_EXPECT(count == 1);
}
@@ -923,8 +923,8 @@ public:
// unmasked frame from client
{
echo_server es{log, kind::async_client};
boost::asio::io_service ios;
stream<test::stream> ws{ios};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc};
ws.next_layer().connect(es.stream());
es.async_handshake();
ws.accept();
@@ -942,8 +942,8 @@ public:
// chopped control frame payload
{
echo_server es{log};
boost::asio::io_service ios;
stream<test::stream> ws{ios};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
ws.next_layer().append(
@@ -958,11 +958,11 @@ public:
BEAST_EXPECTS(! ec, ec.message());
BEAST_EXPECT(to_string(b.data()) == "**");
});
ios.run_one();
ioc.run_one();
es.stream().write_some(
boost::asio::buffer(
"*" "\x81\x02**"));
ios.run();
ioc.run();
BEAST_EXPECT(count == 1);
}
@@ -981,11 +981,11 @@ public:
};
char buf[32];
stream<test::stream> ws{ios_};
stream<test::stream> ws{ioc_};
stream<test::stream>::read_some_op<
boost::asio::mutable_buffers_1,
boost::asio::mutable_buffer,
handler> op{handler{}, ws,
boost::asio::mutable_buffers_1{
boost::asio::mutable_buffer{
buf, sizeof(buf)}};
using boost::asio::asio_handler_is_continuation;
asio_handler_is_continuation(&op);
@@ -998,7 +998,7 @@ public:
};
multi_buffer b;
stream<test::stream> ws{ios_};
stream<test::stream> ws{ioc_};
stream<test::stream>::read_op<
multi_buffer, handler> op{
handler{}, ws, b, 32, true};
@@ -1014,8 +1014,8 @@ public:
for(std::size_t i = 0; i < 100; ++i)
{
echo_server es{log, kind::async};
boost::asio::io_service ios;
stream<test::stream> ws{ios};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
// too-big message frame indicates payload of 2^64-1
@@ -1033,14 +1033,14 @@ public:
testIssue807()
{
echo_server es{log};
boost::asio::io_service ios;
stream<test::stream> ws{ios};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
ws.write(sbuf("Hello, world!"));
char buf[4];
boost::asio::mutable_buffers_1 cb{buf, 0};
auto const n = ws.read_some(cb);
boost::asio::mutable_buffer b{buf, 0};
auto const n = ws.read_some(b);
BEAST_EXPECT(n == 0);
}
+3 -3
View File
@@ -22,7 +22,7 @@ public:
void
testOptions()
{
stream<test::stream> ws{ios_};
stream<test::stream> ws{ioc_};
ws.auto_fragment(true);
ws.write_buffer_size(2048);
ws.binary(false);
@@ -40,7 +40,7 @@ public:
auto const bad =
[&](permessage_deflate const& pmd)
{
stream<test::stream> ws{ios_};
stream<test::stream> ws{ioc_};
try
{
ws.set_option(pmd);
@@ -105,7 +105,7 @@ public:
run() override
{
BOOST_STATIC_ASSERT(std::is_constructible<
stream<test::stream>, boost::asio::io_service&>::value);
stream<test::stream>, boost::asio::io_context&>::value);
BOOST_STATIC_ASSERT(std::is_move_constructible<
stream<test::stream>>::value);
+22 -20
View File
@@ -10,12 +10,14 @@
#ifndef BEAST_TEST_WEBSOCKET_TEST_HPP
#define BEAST_TEST_WEBSOCKET_TEST_HPP
#include <boost/beast/core/buffers_prefix.hpp>
#include <boost/beast/core/ostream.hpp>
#include <boost/beast/core/multi_buffer.hpp>
#include <boost/beast/websocket/stream.hpp>
#include <boost/beast/test/stream.hpp>
#include <boost/beast/test/yield_to.hpp>
#include <boost/beast/unit_test/suite.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/optional.hpp>
#include <array>
@@ -51,9 +53,10 @@ public:
};
std::ostream& log_;
boost::asio::io_service ios_;
boost::asio::io_context ioc_;
boost::optional<
boost::asio::io_service::work> work_;
boost::asio::executor_work_guard<
boost::asio::io_context::executor_type>> work_;
static_buffer<buf_size> buffer_;
test::stream ts_;
std::thread t_;
@@ -66,8 +69,8 @@ public:
std::ostream& log,
kind k = kind::sync)
: log_(log)
, work_(ios_)
, ts_(ios_)
, work_(ioc_.get_executor())
, ts_(ioc_)
, ws_(ts_)
{
permessage_deflate pmd;
@@ -83,12 +86,12 @@ public:
break;
case kind::async:
t_ = std::thread{[&]{ ios_.run(); }};
t_ = std::thread{[&]{ ioc_.run(); }};
do_accept();
break;
case kind::async_client:
t_ = std::thread{[&]{ ios_.run(); }};
t_ = std::thread{[&]{ ioc_.run(); }};
break;
}
}
@@ -118,7 +121,7 @@ public:
void
async_close()
{
ios_.post(
boost::asio::post(ioc_,
[&]
{
if(ws_.is_open())
@@ -293,7 +296,7 @@ public:
doFailLoop(
[&](test::fail_counter& fc)
{
test::stream ts{ios_, fc};
test::stream ts{ioc_, fc};
f(ts);
ts.close();
}
@@ -316,7 +319,7 @@ public:
for(n = 0; n < limit; ++n)
{
test::fail_counter fc{n};
test::stream ts{ios_, fc};
test::stream ts{ioc_, fc};
ws_type ws{ts};
ws.set_option(pmd);
@@ -363,13 +366,12 @@ public:
std::string
to_string(ConstBufferSequence const& bs)
{
using boost::asio::buffer_cast;
using boost::asio::buffer_size;
std::string s;
s.reserve(buffer_size(bs));
for(boost::asio::const_buffer b : bs)
s.append(buffer_cast<char const*>(b),
buffer_size(b));
for(auto b : beast::detail::buffers_range(bs))
s.append(
reinterpret_cast<char const*>(b.data()),
b.size());
return s;
}
@@ -413,10 +415,10 @@ public:
template<std::size_t N>
static
boost::asio::const_buffers_1
boost::asio::const_buffer
sbuf(const char (&s)[N])
{
return boost::asio::const_buffers_1(&s[0], N-1);
return boost::asio::const_buffer(&s[0], N-1);
}
template<
@@ -436,14 +438,14 @@ public:
template<class Pred>
bool
run_until(boost::asio::io_service& ios,
run_until(boost::asio::io_context& ioc,
std::size_t limit, Pred&& pred)
{
for(std::size_t i = 0; i < limit; ++i)
{
if(pred())
return true;
ios.run_one();
ioc.run_one();
}
return false;
}
@@ -451,9 +453,9 @@ public:
template<class Pred>
bool
run_until(
boost::asio::io_service& ios, Pred&& pred)
boost::asio::io_context& ioc, Pred&& pred)
{
return run_until(ios, 100, pred);
return run_until(ioc, 100, pred);
}
inline
+5 -5
View File
@@ -230,7 +230,7 @@ public:
void
testFourByteSequence()
{
using boost::asio::const_buffers_1;
using boost::asio::const_buffer;
utf8_checker utf8;
std::uint8_t buf[4];
for(auto i = 240; i <= 244; ++i)
@@ -364,7 +364,6 @@ public:
void
testWithStreamBuffer()
{
using namespace boost::asio;
{
// Valid UTF8 encoded text
std::vector<std::vector<std::uint8_t>> const data{{
@@ -395,13 +394,14 @@ public:
static std::size_t constexpr size = 3;
std::size_t n = s.size();
buffers_suffix<
boost::asio::const_buffers_1> cb{
boost::asio::const_buffers_1(s.data(), n)};
boost::asio::const_buffer> cb{
boost::asio::const_buffer(s.data(), n)};
multi_buffer b;
while(n)
{
auto const amount = (std::min)(n, size);
b.commit(buffer_copy(b.prepare(amount), cb));
b.commit(boost::asio::buffer_copy(
b.prepare(amount), cb));
cb.consume(amount);
n -= amount;
}
+35 -35
View File
@@ -32,7 +32,7 @@ public:
// already closed
{
echo_server es{log};
stream<test::stream> ws{ios_};
stream<test::stream> ws{ioc_};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
ws.close({});
@@ -255,8 +255,8 @@ public:
doFailLoop([&](test::fail_counter& fc)
{
echo_server es{log};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
std::size_t count = 0;
@@ -280,7 +280,7 @@ public:
BEAST_EXPECT(n == 1);
});
BEAST_EXPECT(count == 0);
ios.run();
ioc.run();
BEAST_EXPECT(count == 2);
});
@@ -288,8 +288,8 @@ public:
doFailLoop([&](test::fail_counter& fc)
{
echo_server es{log};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
std::size_t count = 0;
@@ -312,7 +312,7 @@ public:
system_error{ec});
});
BEAST_EXPECT(count == 0);
ios.run();
ioc.run();
BEAST_EXPECT(count == 2);
});
@@ -320,8 +320,8 @@ public:
doFailLoop([&](test::fail_counter& fc)
{
echo_server es{log};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
// add a ping and message to the input
@@ -339,8 +339,8 @@ public:
});
while(! ws.wr_block_)
{
ios.run_one();
if(! BEAST_EXPECT(! ios.stopped()))
ioc.run_one();
if(! BEAST_EXPECT(! ioc.stopped()))
break;
}
BEAST_EXPECT(count == 0);
@@ -354,7 +354,7 @@ public:
BEAST_EXPECT(n == 1);
});
BEAST_EXPECT(count == 0);
ios.run();
ioc.run();
BEAST_EXPECT(count == 2);
});
@@ -362,8 +362,8 @@ public:
doFailLoop([&](test::fail_counter& fc)
{
echo_server es{log, kind::async_client};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
es.async_handshake();
ws.accept();
@@ -388,7 +388,7 @@ public:
BOOST_THROW_EXCEPTION(
system_error{ec});
});
ios.run();
ioc.run();
BEAST_EXPECT(count == 2);
});
@@ -396,8 +396,8 @@ public:
doFailLoop([&](test::fail_counter& fc)
{
echo_server es{log, kind::async_client};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
es.async_handshake();
ws.accept();
@@ -422,7 +422,7 @@ public:
BOOST_THROW_EXCEPTION(
system_error{ec});
});
ios.run();
ioc.run();
BEAST_EXPECT(count == 2);
});
@@ -431,8 +431,8 @@ public:
{
echo_server es{log};
error_code ec;
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
std::size_t count = 0;
@@ -456,7 +456,7 @@ public:
BOOST_THROW_EXCEPTION(
system_error{ec});
});
ios.run();
ioc.run();
});
// suspend on ping: mask, frag
@@ -464,8 +464,8 @@ public:
{
echo_server es{log};
error_code ec;
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
std::size_t count = 0;
@@ -489,15 +489,15 @@ public:
BOOST_THROW_EXCEPTION(
system_error{ec});
});
ios.run();
ioc.run();
});
// suspend on ping: deflate
doFailLoop([&](test::fail_counter& fc)
{
echo_server es{log, kind::async};
boost::asio::io_service ios;
stream<test::stream> ws{ios, fc};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
{
permessage_deflate pmd;
pmd.client_enable = true;
@@ -527,7 +527,7 @@ public:
BOOST_THROW_EXCEPTION(
system_error{ec});
});
ios.run();
ioc.run();
});
}
@@ -540,8 +540,8 @@ public:
{
echo_server es{log, i==1 ?
kind::async : kind::sync};
boost::asio::io_service ios;
stream<test::stream> ws{ios};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc};
ws.next_layer().connect(es.stream());
error_code ec;
@@ -557,7 +557,7 @@ public:
if(! BEAST_EXPECTS(! ec, ec.message()))
break;
//
// Destruction of the io_service will cause destruction
// Destruction of the io_context will cause destruction
// of the write_some_op without invoking the final handler.
//
break;
@@ -577,8 +577,8 @@ public:
{
echo_server es{log, i==1 ?
kind::async : kind::sync};
boost::asio::io_service ios;
stream<test::stream> ws{ios};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc};
ws.next_layer().connect(es.stream());
error_code ec;
@@ -602,11 +602,11 @@ public:
};
char buf[32];
stream<test::stream> ws{ios_};
stream<test::stream> ws{ioc_};
stream<test::stream>::write_some_op<
boost::asio::const_buffers_1,
boost::asio::const_buffer,
handler> op{handler{}, ws, true,
boost::asio::const_buffers_1{
boost::asio::const_buffer{
buf, sizeof(buf)}};
using boost::asio::asio_handler_is_continuation;
asio_handler_is_continuation(&op);
+5 -7
View File
@@ -67,15 +67,13 @@ public:
fill(MutableBufferSequence const& buffers)
{
std::size_t n = 0;
using boost::asio::buffer_cast;
using boost::asio::buffer_size;
for(boost::asio::mutable_buffer buffer : buffers)
for(auto b : beast::detail::buffers_range(buffers))
{
std::fill(
buffer_cast<char*>(buffer),
buffer_cast<char*>(buffer) +
buffer_size(buffer), '\0');
n += buffer_size(buffer);
reinterpret_cast<char*>(b.data()),
reinterpret_cast<char*>(b.data()) +
b.size(), '\0');
n += b.size();
}
return n;
}
+4 -6
View File
@@ -42,13 +42,11 @@ public:
std::string
to_string(ConstBufferSequence const& bs)
{
using boost::asio::buffer_cast;
using boost::asio::buffer_size;
std::string s;
s.reserve(buffer_size(bs));
for(boost::asio::const_buffer b : bs)
s.append(buffer_cast<char const*>(b),
buffer_size(b));
for(auto b : beast::detail::buffers_range(bs))
s.append(reinterpret_cast<char const*>(b.data()),
b.size());
return s;
}
@@ -172,7 +170,7 @@ public:
isRequest, bench_parser<isRequest, Body, Fields>>
{
using mutable_buffers_type =
boost::asio::mutable_buffers_1;
boost::asio::mutable_buffer;
void
on_request_impl(verb, string_view,
+4 -6
View File
@@ -264,17 +264,15 @@ std::size_t
nodejs_basic_parser<Derived>::write(
ConstBufferSequence const& buffers, error_code& ec)
{
static_assert(beast::is_const_buffer_sequence<
static_assert(boost::asio::is_const_buffer_sequence<
ConstBufferSequence>::value,
"ConstBufferSequence requirements not met");
using boost::asio::buffer_cast;
using boost::asio::buffer_size;
std::size_t bytes_used = 0;
for(boost::asio::const_buffer buffer : buffers)
for(auto buffer : beast::detail::buffers_range(buffers))
{
auto const n = write(
buffer_cast<void const*>(buffer),
buffer_size(buffer), ec);
reinterpret_cast<void const*>(buffer.data()),
buffer.size(), ec);
if(ec)
return 0;
bytes_used += n;
+30 -11
View File
@@ -39,19 +39,37 @@ namespace ws = boost::beast::websocket;
namespace ph = std::placeholders;
using error_code = boost::beast::error_code;
class test_buffer : public asio::const_buffers_1
class test_buffer
{
char data_[4096];
boost::asio::const_buffer b_;
public:
using const_iterator =
boost::asio::const_buffer const*;
using value_type = boost::asio::const_buffer;
test_buffer()
: asio::const_buffers_1(data_, sizeof(data_))
: b_(data_, sizeof(data_))
{
std::mt19937_64 rng;
std::uniform_int_distribution<unsigned short> dist;
for(auto& c : data_)
c = static_cast<unsigned char>(dist(rng));
}
const_iterator
begin() const
{
return &b_;
}
const_iterator
end() const
{
return begin() + 1;
}
};
class report
@@ -96,7 +114,8 @@ class connection
std::size_t messages_;
report& rep_;
test_buffer const& tb_;
asio::io_service::strand strand_;
asio::strand<
asio::io_context::executor_type> strand_;
boost::beast::multi_buffer buffer_;
std::mt19937_64 rng_;
std::size_t count_ = 0;
@@ -105,18 +124,18 @@ class connection
public:
connection(
asio::io_service& ios,
asio::io_context& ioc,
tcp::endpoint const& ep,
std::size_t messages,
bool deflate,
report& rep,
test_buffer const& tb)
: ws_(ios)
: ws_(ioc)
, ep_(ep)
, messages_(messages)
, rep_(rep)
, tb_(tb)
, strand_(ios)
, strand_(ioc.get_executor())
{
ws::permessage_deflate pmd;
pmd.client_enable = deflate;
@@ -274,7 +293,7 @@ main(int argc, char** argv)
return EXIT_FAILURE;
}
auto const address = ip::address::from_string(argv[1]);
auto const address = boost::asio::ip::make_address(argv[1]);
auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
auto const trials = static_cast<std::size_t>(std::atoi(argv[3]));
auto const messages= static_cast<std::size_t>(std::atoi(argv[4]));
@@ -286,12 +305,12 @@ main(int argc, char** argv)
for(auto i = trials; i != 0; --i)
{
report rep;
boost::asio::io_service ios{1};
boost::asio::io_context ioc{1};
for(auto j = workers; j; --j)
{
auto sp =
std::make_shared<connection>(
ios,
ioc,
tcp::endpoint{address, port},
work,
deflate,
@@ -304,9 +323,9 @@ main(int argc, char** argv)
if(threads > 1)
{
tv.reserve(threads);
tv.emplace_back([&ios]{ ios.run(); });
tv.emplace_back([&ioc]{ ioc.run(); });
}
ios.run();
ioc.run();
for(auto& t : tv)
t.join();
auto const elapsed = clock.elapsed();
+2 -2
View File
@@ -50,7 +50,7 @@ public:
testRead()
{
{
test::stream ts{ios_, "\x16***"};
test::stream ts{ioc_, "\x16***"};
error_code ec;
flat_buffer b;
auto const result = detect_ssl(ts, b, ec);
@@ -60,7 +60,7 @@ public:
yield_to(
[&](yield_context yield)
{
test::stream ts{ios_, "\x16***"};
test::stream ts{ioc_, "\x16***"};
error_code ec;
flat_buffer b;
auto const result =
+9 -8
View File
@@ -27,12 +27,12 @@ void fxx()
//
using namespace boost::beast;
boost::asio::io_service ios;
boost::asio::io_service::work work{ios};
std::thread t{[&](){ ios.run(); }};
boost::asio::io_context ioc;
auto work = boost::asio::make_work_guard(ioc);
std::thread t{[&](){ ioc.run(); }};
error_code ec;
boost::asio::ip::tcp::socket sock{ios};
boost::asio::ip::tcp::socket sock{ioc};
//]
@@ -40,9 +40,10 @@ boost::asio::ip::tcp::socket sock{ios};
//[snippet_core_2
char const* const host = "www.example.com";
boost::asio::ip::tcp::resolver r{ios};
boost::asio::ip::tcp::socket stream{ios};
boost::asio::connect(stream, r.resolve({host, "http"}));
boost::asio::ip::tcp::resolver r{ioc};
boost::asio::ip::tcp::socket stream{ioc};
auto const results = r.resolve(host, "http");
boost::asio::connect(stream, results.begin(), results.end());
// At this point `stream` is a connected to a remote
// host and may be used to perform stream operations.
@@ -59,7 +60,7 @@ void write_string(SyncWriteStream& stream, string_view s)
{
static_assert(is_sync_write_stream<SyncWriteStream>::value,
"SyncWriteStream requirements not met");
boost::asio::write(stream, boost::asio::const_buffers_1(s.data(), s.size()));
boost::asio::write(stream, boost::asio::const_buffer(s.data(), s.size()));
}
//]
+1 -1
View File
@@ -53,7 +53,7 @@ struct BodyReader
{
public:
/// The type of buffer returned by `get`.
using const_buffers_type = boost::asio::const_buffers_1;
using const_buffers_type = boost::asio::const_buffer;
/** Construct the reader.
+16 -17
View File
@@ -13,6 +13,7 @@
#include <boost/beast/core/read_size.hpp>
#include <boost/beast/core/ostream.hpp>
#include <boost/beast/core/detail/clamp.hpp>
#include <boost/beast/core/detail/type_traits.hpp>
#include <boost/beast/http/chunk_encode.hpp>
#include <boost/beast/http/parser.hpp>
#include <boost/beast/http/read.hpp>
@@ -57,13 +58,11 @@ public:
std::string
to_string(ConstBufferSequence const& bs)
{
using boost::asio::buffer_cast;
using boost::asio::buffer_size;
std::string s;
s.reserve(buffer_size(bs));
for(boost::asio::const_buffer b : bs)
s.append(buffer_cast<char const*>(b),
buffer_size(b));
for(auto b : beast::detail::buffers_range(bs))
s.append(reinterpret_cast<
char const*>(b.data()), b.size());
return s;
}
@@ -71,7 +70,7 @@ public:
bool
equal_body(string_view sv, string_view body)
{
test::stream ts{ios_, sv};
test::stream ts{ioc_, sv};
message<isRequest, string_body, fields> m;
multi_buffer b;
ts.close_remote();
@@ -90,7 +89,7 @@ public:
void
doExpect100Continue()
{
test::stream ts{ios_}, tr{ios_};
test::stream ts{ioc_}, tr{ioc_};
ts.connect(tr);
yield_to(
[&](yield_context)
@@ -123,10 +122,10 @@ public:
doCgiResponse()
{
std::string const s = "Hello, world!";
test::stream t0{ios_, s};
test::stream t0{ioc_, s};
t0.read_size(3);
t0.close_remote();
test::stream t1{ios_}, t1r{ios_};
test::stream t1{ioc_}, t1r{ioc_};
t1.connect(t1r);
error_code ec;
send_cgi_response(t0, t1, ec);
@@ -145,10 +144,10 @@ public:
req.body() = "Hello, world!";
req.prepare_payload();
test::stream ds{ios_}, dsr{ios_};
test::stream ds{ioc_}, dsr{ioc_};
ds.connect(dsr);
dsr.read_size(3);
test::stream us{ios_}, usr{ios_};
test::stream us{ioc_}, usr{ioc_};
us.connect(usr);
us.write_size(3);
@@ -241,7 +240,7 @@ public:
void
doHEAD()
{
test::stream ts{ios_}, tr{ios_};
test::stream ts{ioc_}, tr{ioc_};
ts.connect(tr);
yield_to(
[&](yield_context)
@@ -280,7 +279,7 @@ public:
void
doDeferredBody()
{
test::stream ts(ios_,
test::stream ts(ioc_,
"POST / HTTP/1.1\r\n"
"User-Agent: test\r\n"
"Content-Type: multipart/form-data\r\n"
@@ -299,7 +298,7 @@ public:
void
doIncrementalRead()
{
test::stream ts{ios_};
test::stream ts{ioc_};
std::string s(2048, '*');
ostream(ts.buffer()) <<
"HTTP/1.1 200 OK\r\n"
@@ -323,10 +322,10 @@ public:
auto const buf =
[](string_view s)
{
return boost::asio::const_buffers_1{
return boost::asio::const_buffer{
s.data(), s.size()};
};
test::stream ts{ios_}, tr{ios_};
test::stream ts{ioc_}, tr{ioc_};
ts.connect(tr);
response<empty_body> res{status::ok, 11};
@@ -394,7 +393,7 @@ public:
void
doExplicitChunkParse()
{
test::stream ts(ios_,
test::stream ts(ioc_,
"HTTP/1.1 200 OK\r\n"
"Server: test\r\n"
"Trailer: Expires, Content-MD5\r\n"
+7 -7
View File
@@ -26,20 +26,20 @@ namespace doc_http_snippets {
//[http_snippet_17
// This function returns the buffer containing the next chunk body
boost::asio::const_buffers_1 get_next_chunk_body();
boost::asio::const_buffer get_next_chunk_body();
//]
boost::asio::const_buffers_1 get_next_chunk_body()
boost::asio::const_buffer get_next_chunk_body()
{
return {nullptr, 0};
}
void fxx() {
boost::asio::io_service ios;
boost::asio::io_service::work work{ios};
std::thread t{[&](){ ios.run(); }};
boost::asio::ip::tcp::socket sock{ios};
boost::asio::io_context ioc;
auto work = boost::asio::make_work_guard(ioc);
std::thread t{[&](){ ioc.run(); }};
boost::asio::ip::tcp::socket sock{ioc};
{
//[http_snippet_2
@@ -270,7 +270,7 @@ void fxx() {
"Content-MD5: f4a5c16584f03d90\r\n"
"Expires: never\r\n"
"\r\n";
boost::asio::write(sock, make_chunk_last(boost::asio::const_buffers_1{ext.data(), ext.size()}));
boost::asio::write(sock, make_chunk_last(boost::asio::const_buffer{ext.data(), ext.size()}));
//]
}
+22 -21
View File
@@ -27,15 +27,15 @@ namespace doc_ws_snippets {
void fxx() {
boost::asio::io_service ios;
boost::asio::io_service::work work{ios};
std::thread t{[&](){ ios.run(); }};
boost::asio::io_context ioc;
auto work = boost::asio::make_work_guard(ioc);
std::thread t{[&](){ ioc.run(); }};
error_code ec;
boost::asio::ip::tcp::socket sock{ios};
boost::asio::ip::tcp::socket sock{ioc};
{
//[ws_snippet_2
stream<boost::asio::ip::tcp::socket> ws{ios};
stream<boost::asio::ip::tcp::socket> ws{ioc};
//]
}
@@ -58,22 +58,23 @@ boost::asio::ip::tcp::socket sock{ios};
{
//[ws_snippet_6
std::string const host = "mywebapp.com";
boost::asio::ip::tcp::resolver r{ios};
stream<boost::asio::ip::tcp::socket> ws{ios};
boost::asio::connect(ws.next_layer(), r.resolve({host, "ws"}));
boost::asio::ip::tcp::resolver r{ioc};
stream<boost::asio::ip::tcp::socket> ws{ioc};
auto const results = r.resolve(host, "ws");
boost::asio::connect(ws.next_layer(), results.begin(), results.end());
//]
}
{
//[ws_snippet_7
boost::asio::ip::tcp::acceptor acceptor{ios};
stream<boost::asio::ip::tcp::socket> ws{acceptor.get_io_service()};
boost::asio::ip::tcp::acceptor acceptor{ioc};
stream<boost::asio::ip::tcp::socket> ws{acceptor.get_executor().context()};
acceptor.accept(ws.next_layer());
//]
}
{
stream<boost::asio::ip::tcp::socket> ws{ios};
stream<boost::asio::ip::tcp::socket> ws{ioc};
//[ws_snippet_8
ws.handshake("localhost", "/");
//]
@@ -137,7 +138,7 @@ boost::asio::ip::tcp::socket sock{ios};
}
{
stream<boost::asio::ip::tcp::socket> ws{ios};
stream<boost::asio::ip::tcp::socket> ws{ioc};
//[ws_snippet_14
// Read into our buffer until we reach the end of the HTTP request.
// No parsing takes place here, we are just accumulating data.
@@ -149,7 +150,7 @@ boost::asio::ip::tcp::socket sock{ios};
//]
}
{
stream<boost::asio::ip::tcp::socket> ws{ios};
stream<boost::asio::ip::tcp::socket> ws{ioc};
//[ws_snippet_15
multi_buffer buffer;
ws.read(buffer);
@@ -161,7 +162,7 @@ boost::asio::ip::tcp::socket sock{ios};
}
{
stream<boost::asio::ip::tcp::socket> ws{ios};
stream<boost::asio::ip::tcp::socket> ws{ioc};
//[ws_snippet_16
multi_buffer buffer;
for(;;)
@@ -187,7 +188,7 @@ boost::asio::ip::tcp::socket sock{ios};
}
{
stream<boost::asio::ip::tcp::socket> ws{ios};
stream<boost::asio::ip::tcp::socket> ws{ioc};
//[ws_snippet_17
auto cb =
[](frame_type kind, string_view payload)
@@ -325,16 +326,16 @@ namespace doc_wss_snippets {
void fxx() {
boost::asio::io_service ios;
boost::asio::io_service::work work{ios};
std::thread t{[&](){ ios.run(); }};
boost::asio::io_context ioc;
auto work = boost::asio::make_work_guard(ioc);
std::thread t{[&](){ ioc.run(); }};
error_code ec;
boost::asio::ip::tcp::socket sock{ios};
boost::asio::ip::tcp::socket sock{ioc};
{
//[wss_snippet_2
boost::asio::ssl::context ctx{boost::asio::ssl::context::sslv23};
stream<boost::asio::ssl::stream<boost::asio::ip::tcp::socket>> wss{ios, ctx};
stream<boost::asio::ssl::stream<boost::asio::ip::tcp::socket>> wss{ioc, ctx};
//]
}
@@ -342,7 +343,7 @@ boost::asio::ip::tcp::socket sock{ios};
//[wss_snippet_3
boost::asio::ip::tcp::endpoint ep;
boost::asio::ssl::context ctx{boost::asio::ssl::context::sslv23};
stream<boost::asio::ssl::stream<boost::asio::ip::tcp::socket>> ws{ios, ctx};
stream<boost::asio::ssl::stream<boost::asio::ip::tcp::socket>> ws{ioc, ctx};
// connect the underlying TCP/IP socket
ws.next_layer().next_layer().connect(ep);
-1
View File
@@ -22,6 +22,5 @@ add_executable (tests-example-common
server_certificate.cpp
session_alloc.cpp
ssl_stream.cpp
write_msg.cpp
main.cpp
)
-1
View File
@@ -13,7 +13,6 @@ local SOURCES =
server_certificate.cpp
session_alloc.cpp
ssl_stream.cpp
write_msg.cpp
;
local RUN_TESTS ;
-12
View File
@@ -1,12 +0,0 @@
//
// 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 "example/common/write_msg.hpp"
@@ -21,14 +21,14 @@ inline
void
sig_wait()
{
boost::asio::io_service ios;
boost::asio::io_context ioc;
boost::asio::signal_set signals(
ios, SIGINT, SIGTERM);
ioc, SIGINT, SIGTERM);
signals.async_wait(
[&](boost::system::error_code const&, int)
{
});
ios.run();
ioc.run();
}
} // test
+108 -68
View File
@@ -10,15 +10,17 @@
#ifndef BOOST_BEAST_TEST_STREAM_HPP
#define BOOST_BEAST_TEST_STREAM_HPP
#include <boost/beast/core/async_result.hpp>
#include <boost/beast/core/bind_handler.hpp>
#include <boost/beast/core/buffers_prefix.hpp>
#include <boost/beast/core/flat_buffer.hpp>
#include <boost/beast/core/string.hpp>
#include <boost/beast/core/type_traits.hpp>
#include <boost/beast/websocket/teardown.hpp>
#include <boost/beast/test/fail_counter.hpp>
#include <boost/asio/async_result.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/post.hpp>
#include <boost/assert.hpp>
#include <boost/optional.hpp>
#include <boost/throw_exception.hpp>
@@ -68,7 +70,7 @@ class stream
flat_buffer b;
std::condition_variable cv;
std::unique_ptr<read_op> op;
boost::asio::io_service& ios;
boost::asio::io_context& ioc;
status code = status::ok;
fail_counter* fc = nullptr;
std::size_t nread = 0;
@@ -85,9 +87,9 @@ class stream
explicit
state(
boost::asio::io_service& ios_,
boost::asio::io_context& ioc_,
fail_counter* fc_)
: ios(ios_)
: ioc(ioc_)
, fc(fc_)
{
}
@@ -139,7 +141,7 @@ public:
stream(stream&& other)
{
auto in = std::make_shared<state>(
other.in_->ios, other.in_->fc);
other.in_->ioc, other.in_->fc);
in_ = std::move(other.in_);
out_ = std::move(other.out_);
other.in_ = in;
@@ -150,7 +152,7 @@ public:
operator=(stream&& other)
{
auto in = std::make_shared<state>(
other.in_->ios, other.in_->fc);
other.in_->ioc, other.in_->fc);
in_ = std::move(other.in_);
out_ = std::move(other.out_);
other.in_ = in;
@@ -159,24 +161,24 @@ public:
/// Constructor
explicit
stream(boost::asio::io_service& ios)
: in_(std::make_shared<state>(ios, nullptr))
stream(boost::asio::io_context& ioc)
: in_(std::make_shared<state>(ioc, nullptr))
{
}
/// Constructor
stream(
boost::asio::io_service& ios,
boost::asio::io_context& ioc,
fail_counter& fc)
: in_(std::make_shared<state>(ios, &fc))
: in_(std::make_shared<state>(ioc, &fc))
{
}
/// Constructor
stream(
boost::asio::io_service& ios,
boost::asio::io_context& ioc,
string_view s)
: in_(std::make_shared<state>(ios, nullptr))
: in_(std::make_shared<state>(ioc, nullptr))
{
using boost::asio::buffer;
using boost::asio::buffer_copy;
@@ -187,10 +189,10 @@ public:
/// Constructor
stream(
boost::asio::io_service& ios,
boost::asio::io_context& ioc,
fail_counter& fc,
string_view s)
: in_(std::make_shared<state>(ios, &fc))
: in_(std::make_shared<state>(ioc, &fc))
{
using boost::asio::buffer;
using boost::asio::buffer_copy;
@@ -209,12 +211,16 @@ public:
remote.out_ = in_;
}
/// Return the `io_service` associated with the stream
boost::asio::io_service&
get_io_service()
/// The type of the executor associated with the object.
using executor_type =
boost::asio::io_context::executor_type;
/// Return the executor associated with the object.
boost::asio::io_context::executor_type
get_executor() noexcept
{
return in_->ios;
}
return in_->ioc.get_executor();
};
/** Get a reference to the lowest layer
@@ -269,11 +275,11 @@ public:
string_view
str() const
{
using boost::asio::buffer_cast;
using boost::asio::buffer_size;
return {
buffer_cast<char const*>(*in_->b.data().begin()),
buffer_size(*in_->b.data().begin())};
auto const bs = in_->b.data();
if(boost::asio::buffer_size(bs) == 0)
return {};
auto const b = buffers_front(bs);
return {reinterpret_cast<char const*>(b.data()), b.size()};
}
/// Appends a string to the pending input data
@@ -336,8 +342,8 @@ public:
error_code& ec);
template<class MutableBufferSequence, class ReadHandler>
async_return_type<
ReadHandler, void(error_code, std::size_t)>
BOOST_ASIO_INITFN_RESULT_TYPE(
ReadHandler, void(error_code, std::size_t))
async_read_some(MutableBufferSequence const& buffers,
ReadHandler&& handler);
@@ -351,8 +357,8 @@ public:
ConstBufferSequence const& buffers, error_code&);
template<class ConstBufferSequence, class WriteHandler>
async_return_type<
WriteHandler, void(error_code, std::size_t)>
BOOST_ASIO_INITFN_RESULT_TYPE(
WriteHandler, void(error_code, std::size_t))
async_write_some(ConstBufferSequence const& buffers,
WriteHandler&& handler);
@@ -405,7 +411,7 @@ std::size_t
stream::
read_some(MutableBufferSequence const& buffers)
{
static_assert(is_mutable_buffer_sequence<
static_assert(boost::asio::is_mutable_buffer_sequence<
MutableBufferSequence>::value,
"MutableBufferSequence requirements not met");
error_code ec;
@@ -421,7 +427,7 @@ stream::
read_some(MutableBufferSequence const& buffers,
error_code& ec)
{
static_assert(is_mutable_buffer_sequence<
static_assert(boost::asio::is_mutable_buffer_sequence<
MutableBufferSequence>::value,
"MutableBufferSequence requirements not met");
using boost::asio::buffer_copy;
@@ -460,27 +466,31 @@ read_some(MutableBufferSequence const& buffers,
}
template<class MutableBufferSequence, class ReadHandler>
async_return_type<
ReadHandler, void(error_code, std::size_t)>
BOOST_ASIO_INITFN_RESULT_TYPE(
ReadHandler, void(error_code, std::size_t))
stream::
async_read_some(
MutableBufferSequence const& buffers,
ReadHandler&& handler)
{
static_assert(is_mutable_buffer_sequence<
static_assert(boost::asio::is_mutable_buffer_sequence<
MutableBufferSequence>::value,
"MutableBufferSequence requirements not met");
using boost::asio::buffer_copy;
using boost::asio::buffer_size;
BOOST_ASSERT(buffer_size(buffers) > 0);
async_completion<ReadHandler,
boost::asio::async_completion<ReadHandler,
void(error_code, std::size_t)> init{handler};
if(in_->fc)
{
error_code ec;
if(in_->fc->fail(ec))
return in_->ios.post(bind_handler(
init.completion_handler, ec, 0));
return boost::asio::post(
in_->ioc.get_executor(),
bind_handler(
init.completion_handler,
ec,
0));
}
{
std::unique_lock<std::mutex> lock{in_->m};
@@ -493,8 +503,12 @@ async_read_some(
in_->b.consume(bytes_transferred);
lock.unlock();
++in_->nread;
in_->ios.post(bind_handler(init.completion_handler,
error_code{}, bytes_transferred));
boost::asio::post(
in_->ioc.get_executor(),
bind_handler(
init.completion_handler,
error_code{},
bytes_transferred));
}
else if(in_->code != status::ok)
{
@@ -505,15 +519,19 @@ async_read_some(
ec = boost::asio::error::eof;
else if(in_->code == status::reset)
ec = boost::asio::error::connection_reset;
in_->ios.post(bind_handler(
init.completion_handler, ec, 0));
boost::asio::post(
in_->ioc.get_executor(),
bind_handler(
init.completion_handler,
ec,
0));
}
else
{
in_->op.reset(new read_op_impl<handler_type<
ReadHandler, void(error_code, std::size_t)>,
MutableBufferSequence>{*in_, buffers,
init.completion_handler});
in_->op.reset(new read_op_impl<BOOST_ASIO_HANDLER_TYPE(
ReadHandler, void(error_code, std::size_t)),
MutableBufferSequence>{*in_, buffers,
init.completion_handler});
}
}
return init.result.get();
@@ -524,7 +542,7 @@ std::size_t
stream::
write_some(ConstBufferSequence const& buffers)
{
static_assert(is_const_buffer_sequence<
static_assert(boost::asio::is_const_buffer_sequence<
ConstBufferSequence>::value,
"ConstBufferSequence requirements not met");
error_code ec;
@@ -541,7 +559,7 @@ stream::
write_some(
ConstBufferSequence const& buffers, error_code& ec)
{
static_assert(is_const_buffer_sequence<
static_assert(boost::asio::is_const_buffer_sequence<
ConstBufferSequence>::value,
"ConstBufferSequence requirements not met");
using boost::asio::buffer_copy;
@@ -569,31 +587,38 @@ write_some(
}
template<class ConstBufferSequence, class WriteHandler>
async_return_type<
WriteHandler, void(error_code, std::size_t)>
BOOST_ASIO_INITFN_RESULT_TYPE(
WriteHandler, void(error_code, std::size_t))
stream::
async_write_some(ConstBufferSequence const& buffers,
WriteHandler&& handler)
{
static_assert(is_const_buffer_sequence<
static_assert(boost::asio::is_const_buffer_sequence<
ConstBufferSequence>::value,
"ConstBufferSequence requirements not met");
using boost::asio::buffer_copy;
using boost::asio::buffer_size;
async_completion<WriteHandler,
boost::asio::async_completion<WriteHandler,
void(error_code, std::size_t)> init{handler};
auto out = out_.lock();
if(! out)
return in_->ios.post(
bind_handler(init.completion_handler,
boost::asio::error::connection_reset, 0));
return boost::asio::post(
in_->ioc.get_executor(),
bind_handler(
init.completion_handler,
boost::asio::error::connection_reset,
0));
BOOST_ASSERT(out->code == status::ok);
if(in_->fc)
{
error_code ec;
if(in_->fc->fail(ec))
return in_->ios.post(bind_handler(
init.completion_handler, ec, 0));
return boost::asio::post(
in_->ioc.get_executor(),
bind_handler(
init.completion_handler,
ec,
0));
}
auto const n =
(std::min)(buffer_size(buffers), in_->write_max);
@@ -604,8 +629,12 @@ async_write_some(ConstBufferSequence const& buffers,
out->on_write();
lock.unlock();
++in_->nwrite;
in_->ios.post(bind_handler(init.completion_handler,
error_code{}, bytes_transferred));
boost::asio::post(
in_->ioc.get_executor(),
bind_handler(
init.completion_handler,
error_code{},
bytes_transferred));
return init.result.get();
}
@@ -640,7 +669,8 @@ async_teardown(
error_code ec;
if( s.in_->fc &&
s.in_->fc->fail(ec))
return s.get_io_service().post(
return boost::asio::post(
s.get_executor(),
bind_handler(std::move(handler), ec));
s.close();
if( s.in_->fc &&
@@ -649,7 +679,8 @@ async_teardown(
else
ec.assign(0, ec.category());
s.get_io_service().post(
boost::asio::post(
s.get_executor(),
bind_handler(std::move(handler), ec));
}
@@ -664,7 +695,8 @@ class stream::read_op_impl : public stream::read_op
Buffers b_;
Handler h_;
boost::optional<
boost::asio::io_service::work> work_;
boost::asio::executor_work_guard<
boost::asio::io_context::executor_type>> work_;
public:
lambda(lambda&&) = default;
@@ -674,7 +706,7 @@ class stream::read_op_impl : public stream::read_op
: s_(s)
, b_(b)
, h_(std::move(h))
, work_(s_.ios)
, work_(s_.ioc.get_executor())
{
}
@@ -682,14 +714,16 @@ class stream::read_op_impl : public stream::read_op
: s_(s)
, b_(b)
, h_(h)
, work_(s_.ios)
, work_(s_.ioc.get_executor())
{
}
void
post()
{
s_.ios.post(std::move(*this));
boost::asio::post(
s_.ioc.get_executor(),
std::move(*this));
work_ = boost::none;
}
@@ -709,8 +743,12 @@ class stream::read_op_impl : public stream::read_op
Handler h{std::move(h_)};
lock.unlock();
++s.nread;
s.ios.post(bind_handler(std::move(h),
error_code{}, bytes_transferred));
boost::asio::post(
s.ioc.get_executor(),
bind_handler(
std::move(h),
error_code{},
bytes_transferred));
}
else
{
@@ -724,7 +762,9 @@ class stream::read_op_impl : public stream::read_op
ec = boost::asio::error::eof;
else if(s.code == status::reset)
ec = boost::asio::error::connection_reset;
s.ios.post(bind_handler(std::move(h), ec, 0));
boost::asio::post(
s.ioc.get_executor(),
bind_handler(std::move(h), ec, 0));
}
}
};
@@ -754,7 +794,7 @@ inline
stream
connect(stream& to)
{
stream from{to.get_io_service()};
stream from{to.get_executor().context()};
from.connect(to);
return from;
}
@@ -10,7 +10,7 @@
#ifndef BOOST_BEAST_TEST_YIELD_TO_HPP
#define BOOST_BEAST_TEST_YIELD_TO_HPP
#include <boost/asio/io_service.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/optional.hpp>
#include <condition_variable>
@@ -32,10 +32,12 @@ namespace test {
class enable_yield_to
{
protected:
boost::asio::io_service ios_;
boost::asio::io_context ioc_;
private:
boost::optional<boost::asio::io_service::work> work_;
boost::optional<
boost::asio::executor_work_guard<
boost::asio::io_context::executor_type>> work_;
std::vector<std::thread> threads_;
std::mutex m_;
std::condition_variable cv_;
@@ -48,12 +50,12 @@ public:
explicit
enable_yield_to(std::size_t concurrency = 1)
: work_(ios_)
: work_(ioc_.get_executor())
{
threads_.reserve(concurrency);
while(concurrency--)
threads_.emplace_back(
[&]{ ios_.run(); });
[&]{ ioc_.run(); });
}
~enable_yield_to()
@@ -63,11 +65,11 @@ public:
t.join();
}
/// Return the `io_service` associated with the object
boost::asio::io_service&
/// Return the `io_context` associated with the object
boost::asio::io_context&
get_io_service()
{
return ios_;
return ioc_;
}
/** Run one or more functions, each in a coroutine.
@@ -119,7 +121,7 @@ void
enable_yield_to::
spawn(F0&& f, FN&&... fn)
{
boost::asio::spawn(ios_,
boost::asio::spawn(ioc_,
[&](yield_context yield)
{
f(yield);