Add buffer_size

This commit is contained in:
Vinnie Falco
2019-02-03 12:59:11 -08:00
parent 64149f434a
commit 35dbd140d4
64 changed files with 427 additions and 379 deletions
+1
View File
@@ -31,6 +31,7 @@ add_executable (tests-beast-core
async_op_base.cpp
basic_timeout_stream.cpp
bind_handler.cpp
buffer_size.cpp
buffer_traits.cpp
buffered_read_stream.cpp
buffers_adapter.cpp
+1
View File
@@ -19,6 +19,7 @@ local SOURCES =
async_op_base.cpp
basic_timeout_stream.cpp
bind_handler.cpp
buffer_size.cpp
buffer_traits.cpp
buffered_read_stream.cpp
buffers_adapter.cpp
+98
View File
@@ -0,0 +1,98 @@
//
// Copyright (c) 2018 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/buffer_size.hpp>
#include <boost/beast/_experimental/unit_test/suite.hpp>
#include <boost/beast/core/detail/type_traits.hpp>
namespace boost {
namespace beast {
namespace {
struct sequence
{
struct value_type
{
operator net::const_buffer() const noexcept
{
return {"Hello, world!", 13};
}
};
using const_iterator = value_type const*;
const_iterator begin() const noexcept
{
return &v_;
}
const_iterator end() const noexcept
{
return begin() + 1;
}
private:
value_type v_;
};
struct not_sequence
{
};
} // (anon)
class buffer_size_test : public beast::unit_test::suite
{
public:
void
testJavadocs()
{
pass();
}
void
testFunction()
{
BEAST_EXPECT(buffer_size(
net::const_buffer("Hello, world!", 13)) == 13);
BEAST_EXPECT(buffer_size(
net::mutable_buffer{}) == 0);
{
sequence s;
BEAST_EXPECT(buffer_size(s) == 13);
}
{
std::array<net::const_buffer, 2> s({{
net::const_buffer("Hello, world!", 13),
net::const_buffer("Hello, world!", 13)}});
BEAST_EXPECT(buffer_size(s) == 26);
}
BOOST_STATIC_ASSERT(! detail::is_invocable<
detail::buffer_size_impl,
std::size_t(not_sequence const&)>::value);
}
void run() override
{
testFunction();
testJavadocs();
}
};
BEAST_DEFINE_TESTSUITE(beast,core,buffer_size);
} // beast
} // boost
+1 -8
View File
@@ -12,6 +12,7 @@
#include <boost/beast/core/detail/config.hpp>
#include <boost/beast/_experimental/unit_test/suite.hpp>
#include <boost/beast/core/buffer_size.hpp>
#include <boost/beast/core/buffer_traits.hpp>
#include <boost/beast/core/buffers_to_string.hpp>
#include <boost/beast/core/string.hpp>
@@ -116,7 +117,6 @@ void test_mutable_buffers(
MutableBufferSequence const& b,
net::mutable_buffer)
{
using net::buffer_size;
string_view src = "Hello, world!";
BOOST_ASSERT(buffer_size(b) <= src.size());
if(src.size() > buffer_size(b))
@@ -139,8 +139,6 @@ test_buffer_sequence(
net::is_const_buffer_sequence<
ConstBufferSequence>::value);
using net::buffer_size;
using iterator = decltype(
net::buffer_sequence_begin(buffers));
BEAST_EXPECT(sizeof(iterator) > 0);
@@ -183,7 +181,6 @@ test_buffer_sequence(
// bidirectional
{
using net::buffer_size;
auto const first =
net::buffer_sequence_begin(buffers);
auto const last =
@@ -290,8 +287,6 @@ test_mutable_dynamic_buffer(
MutableDynamicBuffer const& b0,
std::true_type)
{
using net::buffer_size;
BOOST_STATIC_ASSERT(
net::is_mutable_buffer_sequence<typename
MutableDynamicBuffer::mutable_data_type>::value);
@@ -372,8 +367,6 @@ void
test_dynamic_buffer(
DynamicBuffer const& b0)
{
using net::buffer_size;
BOOST_STATIC_ASSERT(
net::is_dynamic_buffer<DynamicBuffer>::value);
-1
View File
@@ -80,7 +80,6 @@ public:
void
on_read(error_code ec, std::size_t)
{
using net::buffer;
if(! ec)
{
suite_.expect(s_ ==
+1 -2
View File
@@ -12,6 +12,7 @@
#include "buffer_test.hpp"
#include <boost/beast/core/buffer_size.hpp>
#include <boost/beast/core/multi_buffer.hpp>
#include <boost/beast/core/ostream.hpp>
#include <boost/beast/core/read_size.hpp>
@@ -42,8 +43,6 @@ public:
void
testSpecial()
{
using net::buffer_size;
char s1[13];
buffers_triple tb1(s1, sizeof(s1));
BEAST_EXPECT(buffer_size(tb1) == sizeof(s1));
+5 -11
View File
@@ -13,6 +13,7 @@
#include "buffer_test.hpp"
#include <boost/beast/_experimental/unit_test/suite.hpp>
#include <boost/beast/core/buffer_size.hpp>
#include <boost/beast/core/buffers_prefix.hpp>
#include <boost/beast/core/buffers_suffix.hpp>
#include <boost/asio/buffer.hpp>
@@ -155,8 +156,6 @@ public:
void
testEmpty()
{
using net::buffer_size;
struct empty_sequence
{
using value_type = net::const_buffer;
@@ -275,19 +274,14 @@ public:
void
testGccWarning1()
{
using boost::beast::buffers_cat;
using boost::beast::buffers_suffix;
using net::buffer;
using net::const_buffer;
char out[64];
std::array<const_buffer, 2> buffers{
{buffer("Hello, "), buffer("world!")}};
std::array<net::const_buffer, 2> buffers{
{net::buffer("Hello, "), net::buffer("world!")}};
std::size_t i = 3;
buffers_suffix<std::array<const_buffer, 2>> cb(buffers);
buffers_suffix<std::array<net::const_buffer, 2>> cb(buffers);
cb.consume(i);
net::buffer_copy(
buffer(out),
net::buffer(out),
buffers_cat(cb, cb));
}
+1 -3
View File
@@ -12,6 +12,7 @@
#include "buffer_test.hpp"
#include <boost/beast/core/buffer_size.hpp>
#include <boost/beast/core/buffers_to_string.hpp>
#include <boost/beast/core/type_traits.hpp>
#include <boost/beast/_experimental/unit_test/suite.hpp>
@@ -89,7 +90,6 @@ public:
void
testPrefixes()
{
using net::buffer_size;
std::string s = "Hello, world";
BEAST_EXPECT(s.size() == 12);
for(std::size_t x = 1; x < 4; ++x) {
@@ -118,8 +118,6 @@ public:
void testEmpty()
{
using net::buffer_size;
auto pb0 = buffers_prefix(0, net::mutable_buffer{});
BEAST_EXPECT(buffer_size(pb0) == 0);
auto pb1 = buffers_prefix(1, net::mutable_buffer{});
+1 -2
View File
@@ -12,6 +12,7 @@
#include "buffer_test.hpp"
#include <boost/beast/core/buffer_size.hpp>
#include <boost/beast/core/buffers_cat.hpp>
#include <boost/beast/_experimental/unit_test/suite.hpp>
#include <boost/asio/buffer.hpp>
@@ -80,7 +81,6 @@ public:
// empty sequence
{
using net::buffer_size;
buffers_suffix<net::mutable_buffer> cb(
net::mutable_buffer{});
BEAST_EXPECT(buffer_size(cb) == 0);
@@ -113,7 +113,6 @@ public:
void
testMatrix()
{
using net::buffer_size;
char buf[12];
std::string const s = "Hello, world";
BEAST_EXPECT(s.size() == sizeof(buf));
+1 -2
View File
@@ -12,6 +12,7 @@
#include "buffer_test.hpp"
#include <boost/beast/core/buffer_size.hpp>
#include <boost/beast/core/ostream.hpp>
#include <boost/beast/core/read_size.hpp>
#include <boost/beast/core/string.hpp>
@@ -40,8 +41,6 @@ public:
void
testMembers()
{
using net::buffer_size;
string_view const s = "Hello, world!";
// flat_static_buffer_base
+2 -3
View File
@@ -9,7 +9,9 @@
// Test that header file is self-contained.
#include <boost/beast/core/make_printable.hpp>
#include <boost/beast/_experimental/unit_test/suite.hpp>
#include <boost/beast/core/buffer_size.hpp>
#include <iostream>
#include <sstream>
@@ -25,7 +27,6 @@ public:
void
print (ConstBufferSequence const& buffers)
{
using net::buffer_size;
std::cout <<
"Buffer size: " << buffer_size(buffers) << " bytes\n"
"Buffer data: '" << make_printable(buffers) << "'\n";
@@ -40,8 +41,6 @@ public:
void
testMakePrintable()
{
using net::buffer;
char buf[13];
buffers_triple b(buf, sizeof(buf));
string_view src = "Hello, world!";
+4 -7
View File
@@ -12,6 +12,7 @@
#include "buffer_test.hpp"
#include <boost/beast/core/buffer_size.hpp>
#include <boost/beast/core/ostream.hpp>
#include <boost/beast/core/read_size.hpp>
#include <boost/beast/core/string.hpp>
@@ -577,8 +578,6 @@ public:
void
testMatrix1()
{
using net::buffer_size;
string_view s = "Hello, world";
BEAST_EXPECT(s.size() == 12);
for(std::size_t i = 1; i < 12; ++i) {
@@ -621,8 +620,6 @@ public:
testMatrix2()
{
using namespace test;
using net::buffer;
using net::buffer_size;
std::string const s = "Hello, world";
BEAST_EXPECT(s.size() == 12);
for(std::size_t i = 1; i < 12; ++i) {
@@ -649,7 +646,7 @@ public:
{
auto d = b.prepare(x);
BEAST_EXPECT(buffer_size(d) == x);
b.commit(buffer_copy(d, buffer(s.data(), x)));
b.commit(buffer_copy(d, net::buffer(s.data(), x)));
}
BEAST_EXPECT(b.size() == x);
BEAST_EXPECT(buffer_size(b.data()) == b.size());
@@ -668,7 +665,7 @@ public:
{
auto d = b.prepare(y);
BEAST_EXPECT(buffer_size(d) == y);
b.commit(buffer_copy(d, buffer(s.data()+x, y)));
b.commit(buffer_copy(d, net::buffer(s.data()+x, y)));
}
b.commit(1);
BEAST_EXPECT(b.size() == x + y);
@@ -688,7 +685,7 @@ public:
{
auto d = b.prepare(z);
BEAST_EXPECT(buffer_size(d) == z);
b.commit(buffer_copy(d, buffer(s.data()+x+y, z)));
b.commit(buffer_copy(d, net::buffer(s.data()+x+y, z)));
}
b.commit(2);
BEAST_EXPECT(b.size() == x + y + z);
+1 -2
View File
@@ -12,6 +12,7 @@
#include "buffer_test.hpp"
#include <boost/beast/core/buffer_size.hpp>
#include <boost/beast/core/ostream.hpp>
#include <boost/beast/core/read_size.hpp>
#include <boost/beast/core/string.hpp>
@@ -44,8 +45,6 @@ public:
void
testMembers()
{
using net::buffer_size;
string_view const s = "Hello, world!";
// static_buffer_base
+1 -1
View File
@@ -13,6 +13,7 @@
#include "message_fuzz.hpp"
#include "test_parser.hpp"
#include <boost/beast/core/buffer_size.hpp>
#include <boost/beast/core/buffers_cat.hpp>
#include <boost/beast/core/buffers_prefix.hpp>
#include <boost/beast/core/buffers_suffix.hpp>
@@ -156,7 +157,6 @@ public:
parsegrind(ConstBufferSequence const& buffers,
Test const& test, bool skip = false)
{
using net::buffer_size;
auto const size = buffer_size(buffers);
for(std::size_t i = 1; i < size - 1; ++i)
{
+1 -1
View File
@@ -10,6 +10,7 @@
// Test that header file is self-contained.
#include <boost/beast/http/file_body.hpp>
#include <boost/beast/core/buffer_size.hpp>
#include <boost/beast/core/buffers_prefix.hpp>
#include <boost/beast/core/file_stdio.hpp>
#include <boost/beast/core/flat_buffer.hpp>
@@ -33,7 +34,6 @@ public:
void
operator()(error_code&, ConstBufferSequence const& buffers)
{
using net::buffer_size;
buffer.commit(net::buffer_copy(
buffer.prepare(buffer_size(buffers)),
buffers));
+4 -5
View File
@@ -14,6 +14,7 @@
#include <boost/beast/_experimental/unit_test/suite.hpp>
#include <boost/beast/test/yield_to.hpp>
#include <boost/beast/core/buffer_size.hpp>
#include <boost/beast/core/buffers_suffix.hpp>
#include <boost/beast/core/flat_buffer.hpp>
#include <boost/beast/core/multi_buffer.hpp>
@@ -51,7 +52,6 @@ public:
basic_parser<isRequest, Derived>& p,
error_code& ec)
{
using net::buffer_size;
buffers_suffix<ConstBufferSequence> cb{buffers};
for(;;)
{
@@ -75,13 +75,12 @@ public:
void
doMatrix(string_view s0, F const& f)
{
using net::buffer;
// parse a single buffer
{
auto s = s0;
error_code ec;
parser_type<isRequest> p;
put(buffer(s.data(), s.size()), p, ec);
put(net::buffer(s.data(), s.size()), p, ec);
if(! BEAST_EXPECTS(! ec, ec.message()))
return;
f(p);
@@ -94,7 +93,7 @@ public:
parser_type<isRequest> p;
p.eager(true);
auto used =
p.put(buffer(s.data(), n), ec);
p.put(net::buffer(s.data(), n), ec);
s.remove_prefix(used);
if(ec == error::need_more)
ec = {};
@@ -102,7 +101,7 @@ public:
continue;
BEAST_EXPECT(! p.is_done());
used = p.put(
buffer(s.data(), s.size()), ec);
net::buffer(s.data(), s.size()), ec);
s.remove_prefix(used);
if(! BEAST_EXPECTS(! ec, ec.message()))
continue;
-1
View File
@@ -430,7 +430,6 @@ public:
void
readgrind(string_view s, Pred&& pred)
{
using net::buffer;
for(std::size_t n = 1; n < s.size() - 1; ++n)
{
Parser p;
+1 -1
View File
@@ -10,6 +10,7 @@
// Test that header file is self-contained.
#include <boost/beast/http/serializer.hpp>
#include <boost/beast/core/buffer_size.hpp>
#include <boost/beast/http/string_body.hpp>
#include <boost/beast/_experimental/unit_test/suite.hpp>
@@ -91,7 +92,6 @@ public:
operator()(error_code&,
ConstBufferSequence const& buffers)
{
using net::buffer_size;
size = buffer_size(buffers);
}
};
+1 -1
View File
@@ -10,6 +10,7 @@
// Test that header file is self-contained.
#include <boost/beast/http/span_body.hpp>
#include <boost/beast/core/buffer_size.hpp>
#include <boost/beast/http/message.hpp>
#include <boost/beast/_experimental/unit_test/suite.hpp>
@@ -23,7 +24,6 @@ struct span_body_test
void
testSpanBody()
{
using net::buffer_size;
{
using B = span_body<char const>;
request<B> req;
+7 -10
View File
@@ -124,10 +124,10 @@ public:
std::false_type, // isSplit
std::false_type) // isFinalEmpty
{
using net::buffer;
if(body_.s.empty())
return boost::none;
return {{buffer(body_.s.data(), body_.s.size()), false}};
return {{net::buffer(
body_.s.data(), body_.s.size()), false}};
}
boost::optional<std::pair<const_buffers_type, bool>>
@@ -135,14 +135,13 @@ public:
std::false_type, // isSplit
std::true_type) // isFinalEmpty
{
using net::buffer;
if(body_.s.empty())
return boost::none;
switch(step_)
{
case 0:
step_ = 1;
return {{buffer(
return {{net::buffer(
body_.s.data(), body_.s.size()), true}};
default:
return boost::none;
@@ -154,7 +153,6 @@ public:
std::true_type, // isSplit
std::false_type) // isFinalEmpty
{
using net::buffer;
auto const n = (body_.s.size() + 1) / 2;
switch(step_)
{
@@ -162,10 +160,10 @@ public:
if(n == 0)
return boost::none;
step_ = 1;
return {{buffer(body_.s.data(), n),
return {{net::buffer(body_.s.data(), n),
body_.s.size() > 1}};
default:
return {{buffer(body_.s.data() + n,
return {{net::buffer(body_.s.data() + n,
body_.s.size() - n), false}};
}
}
@@ -175,7 +173,6 @@ public:
std::true_type, // isSplit
std::true_type) // isFinalEmpty
{
using net::buffer;
auto const n = (body_.s.size() + 1) / 2;
switch(step_)
{
@@ -183,11 +180,11 @@ public:
if(n == 0)
return boost::none;
step_ = body_.s.size() > 1 ? 1 : 2;
return {{buffer(body_.s.data(), n), true}};
return {{net::buffer(body_.s.data(), n), true}};
case 1:
BOOST_ASSERT(body_.s.size() > 1);
step_ = 2;
return {{buffer(body_.s.data() + n,
return {{net::buffer(body_.s.data() + n,
body_.s.size() - n), true}};
default:
return boost::none;
+5 -7
View File
@@ -171,8 +171,6 @@ public:
void
testSuspend()
{
using net::buffer;
// suspend on ping
doFailLoop([&](test::fail_count& fc)
{
@@ -374,7 +372,7 @@ public:
"\x88\x00", 2});
std::size_t count = 0;
std::string const s = "Hello, world!";
ws.async_write(buffer(s),
ws.async_write(net::buffer(s),
[&](error_code ec, std::size_t n)
{
if(ec)
@@ -419,7 +417,7 @@ public:
std::size_t count = 0;
multi_buffer b;
std::string const s = "Hello, world!";
ws.async_write(buffer(s),
ws.async_write(net::buffer(s),
[&](error_code ec, std::size_t n)
{
if(ec)
@@ -479,7 +477,7 @@ public:
system_error{ec});
++count;
});
ws.async_write(buffer(s),
ws.async_write(net::buffer(s),
[&](error_code ec, std::size_t)
{
if(ec != net::error::operation_aborted)
@@ -527,7 +525,7 @@ public:
BEAST_EXPECT(
ec == net::error::operation_aborted);
});
ws.async_write(buffer(s),
ws.async_write(net::buffer(s),
[&](error_code ec, std::size_t n)
{
if(ec)
@@ -588,7 +586,7 @@ public:
system_error{ec});
++count;
});
ws.async_write(buffer(s),
ws.async_write(net::buffer(s),
[&](error_code ec, std::size_t)
{
if(ec != net::error::operation_aborted)
+14 -22
View File
@@ -75,8 +75,6 @@ public:
void
doTestRead(Wrap const& w)
{
using net::buffer;
permessage_deflate pmd;
pmd.client_enable = false;
pmd.server_enable = false;
@@ -230,7 +228,7 @@ public:
std::string const s(2000, '*');
ws.auto_fragment(false);
ws.binary(false);
w.write(ws, buffer(s));
w.write(ws, net::buffer(s));
multi_buffer b;
w.read(ws, b);
BEAST_EXPECT(ws.got_text());
@@ -285,7 +283,7 @@ public:
std::string const s = "Hello, world!";
ws.auto_fragment(false);
ws.binary(false);
w.write(ws, buffer(s));
w.write(ws, net::buffer(s));
try
{
multi_buffer b(3);
@@ -306,7 +304,7 @@ public:
auto const s = std::string(2000, '*') +
random_string();
ws.text(true);
w.write(ws, buffer(s));
w.write(ws, net::buffer(s));
doReadTest(w, ws, close_code::bad_payload);
});
@@ -363,7 +361,7 @@ public:
{
std::string const s =
"Hello, world!" "\xc0";
w.write(ws, buffer(s));
w.write(ws, net::buffer(s));
doReadTest(w, ws, close_code::bad_payload);
});
@@ -437,8 +435,6 @@ public:
void
doTestReadDeflate(Wrap const& w)
{
using net::buffer;
permessage_deflate pmd;
pmd.client_enable = true;
pmd.server_enable = true;
@@ -451,7 +447,7 @@ public:
[&](ws_type_t<true>& ws)
{
std::string const s = std::string(128, '*');
w.write(ws, buffer(s));
w.write(ws, net::buffer(s));
ws.read_message_max(32);
doFailTest(w, ws, error::message_too_big);
});
@@ -490,7 +486,7 @@ public:
{
auto const& s = random_string();
ws.binary(true);
w.write(ws, buffer(s));
w.write(ws, net::buffer(s));
multi_buffer b;
w.read(ws, b);
BEAST_EXPECT(buffers_to_string(b.data()) == s);
@@ -504,15 +500,13 @@ public:
permessage_deflate const& pmd,
Wrap const& w)
{
using net::buffer;
// message
doTest(pmd, [&](ws_type& ws)
{
std::string const s = "Hello, world!";
ws.auto_fragment(false);
ws.binary(false);
w.write(ws, buffer(s));
w.write(ws, net::buffer(s));
multi_buffer b;
w.read(ws, b);
BEAST_EXPECT(ws.got_text());
@@ -533,7 +527,7 @@ public:
std::string const s = "Hello, world!";
ws.auto_fragment(false);
ws.binary(false);
w.write(ws, buffer(s));
w.write(ws, net::buffer(s));
multi_buffer b;
w.read(ws, b);
BEAST_EXPECT(ws.got_text());
@@ -552,7 +546,7 @@ public:
{
std::string const s = "";
ws.text(true);
w.write(ws, buffer(s));
w.write(ws, net::buffer(s));
multi_buffer b;
w.read(ws, b);
BEAST_EXPECT(ws.got_text());
@@ -563,10 +557,10 @@ public:
doTest(pmd, [&](ws_type& ws)
{
std::string const s = "Hello";
w.write(ws, buffer(s));
w.write(ws, net::buffer(s));
char buf[3];
auto const bytes_written =
w.read_some(ws, buffer(buf, sizeof(buf)));
w.read_some(ws, net::buffer(buf, sizeof(buf)));
BEAST_EXPECT(bytes_written > 0);
BEAST_EXPECT(
string_view(buf, 3).substr(0, bytes_written) ==
@@ -577,7 +571,7 @@ public:
doTest(pmd, [&](ws_type& ws)
{
std::string const s = "Hello, world!";
w.write(ws, buffer(s));
w.write(ws, net::buffer(s));
multi_buffer b;
auto bytes_written =
w.read_some(ws, 3, b);
@@ -593,7 +587,7 @@ public:
{
auto const& s = random_string();
ws.binary(true);
w.write(ws, buffer(s));
w.write(ws, net::buffer(s));
multi_buffer b;
w.read(ws, b);
BEAST_EXPECT(buffers_to_string(b.data()) == s);
@@ -605,7 +599,7 @@ public:
std::string const s = "\x03\xea\xf0\x28\x8c\xbc";
ws.auto_fragment(false);
ws.text(true);
w.write(ws, buffer(s));
w.write(ws, net::buffer(s));
doReadTest(w, ws, close_code::bad_payload);
});
}
@@ -613,8 +607,6 @@ public:
void
testRead()
{
using net::buffer;
doTestRead<false>(SyncClient{});
doTestRead<true>(SyncClient{});
doTestReadDeflate(SyncClient{});
+2 -7
View File
@@ -12,6 +12,7 @@
#include "test.hpp"
#include <boost/asio/buffer.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/strand.hpp>
#include <boost/asio/write.hpp>
@@ -26,8 +27,6 @@ public:
void
testSuspend()
{
using net::buffer;
#if 1
// suspend on read block
doFailLoop([&](test::fail_count& fc)
{
@@ -59,12 +58,10 @@ public:
ioc.run();
BEAST_EXPECT(count == 2);
});
#endif
// suspend on release read block
doFailLoop([&](test::fail_count& fc)
{
//log << "fc.count()==" << fc.count() << std::endl;
echo_server es{log};
net::io_context ioc;
stream<test::stream> ws{ioc, fc};
@@ -93,7 +90,6 @@ public:
BEAST_EXPECT(count == 2);
});
#if 1
// suspend on write pong
doFailLoop([&](test::fail_count& fc)
{
@@ -118,7 +114,7 @@ public:
++count;
});
BEAST_EXPECT(ws.impl_->rd_block.is_locked());
ws.async_write(buffer(s),
ws.async_write(net::buffer(s),
[&](error_code ec, std::size_t n)
{
if(ec)
@@ -217,7 +213,6 @@ public:
ioc.run();
BEAST_EXPECT(count == 2);
});
#endif
}
void
+1 -1
View File
@@ -10,6 +10,7 @@
#ifndef BEAST_TEST_WEBSOCKET_TEST_HPP
#define BEAST_TEST_WEBSOCKET_TEST_HPP
#include <boost/beast/core/buffer_size.hpp>
#include <boost/beast/core/buffers_prefix.hpp>
#include <boost/beast/core/buffers_to_string.hpp>
#include <boost/beast/core/ostream.hpp>
@@ -434,7 +435,6 @@ public:
DynamicBuffer& buffer,
ConstBufferSequence const& buffers)
{
using net::buffer_size;
buffer.commit(net::buffer_copy(
buffer.prepare(buffer_size(buffers)),
buffers));
+19 -27
View File
@@ -26,8 +26,6 @@ public:
void
doTestWrite(Wrap const& w)
{
using net::buffer;
permessage_deflate pmd;
pmd.client_enable = false;
pmd.server_enable = false;
@@ -59,7 +57,7 @@ public:
ws.auto_fragment(false);
ws.binary(false);
std::string const s = "Hello, world!";
w.write(ws, buffer(s));
w.write(ws, net::buffer(s));
multi_buffer b;
w.read(ws, b);
BEAST_EXPECT(ws.got_text());
@@ -85,8 +83,8 @@ public:
ws.auto_fragment(false);
ws.binary(false);
std::string const s = "Hello, world!";
w.write_some(ws, false, buffer(s.data(), 5));
w.write_some(ws, true, buffer(s.data() + 5, s.size() - 5));
w.write_some(ws, false, net::buffer(s.data(), 5));
w.write_some(ws, true, net::buffer(s.data() + 5, s.size() - 5));
multi_buffer b;
w.read(ws, b);
BEAST_EXPECT(ws.got_text());
@@ -101,8 +99,8 @@ public:
std::size_t const chop = 3;
BOOST_ASSERT(chop < s.size());
w.write_some(ws, false,
buffer(s.data(), chop));
w.write_some(ws, true, buffer(
net::buffer(s.data(), chop));
w.write_some(ws, true, net::buffer(
s.data() + chop, s.size() - chop));
flat_buffer b;
w.read(ws, b);
@@ -115,7 +113,7 @@ public:
{
ws.auto_fragment(false);
std::string const s = "Hello";
w.write(ws, buffer(s));
w.write(ws, net::buffer(s));
flat_buffer b;
w.read(ws, b);
BEAST_EXPECT(buffers_to_string(b.data()) == s);
@@ -128,7 +126,7 @@ public:
ws.auto_fragment(false);
ws.write_buffer_size(16);
std::string const s(32, '*');
w.write(ws, buffer(s));
w.write(ws, net::buffer(s));
flat_buffer b;
w.read(ws, b);
BEAST_EXPECT(buffers_to_string(b.data()) == s);
@@ -140,7 +138,7 @@ public:
{
ws.auto_fragment(true);
std::string const s(16384, '*');
w.write(ws, buffer(s));
w.write(ws, net::buffer(s));
flat_buffer b;
w.read(ws, b);
BEAST_EXPECT(buffers_to_string(b.data()) == s);
@@ -158,7 +156,7 @@ public:
w.accept(ws);
ws.auto_fragment(false);
std::string const s = "Hello";
w.write(ws, buffer(s));
w.write(ws, net::buffer(s));
flat_buffer b;
w.read(ws, b);
BEAST_EXPECT(buffers_to_string(b.data()) == s);
@@ -184,7 +182,7 @@ public:
w.accept(ws);
ws.auto_fragment(true);
std::string const s(16384, '*');
w.write(ws, buffer(s));
w.write(ws, net::buffer(s));
flat_buffer b;
w.read(ws, b);
BEAST_EXPECT(buffers_to_string(b.data()) == s);
@@ -203,8 +201,6 @@ public:
void
doTestWriteDeflate(Wrap const& w)
{
using net::buffer;
permessage_deflate pmd;
pmd.client_enable = true;
pmd.server_enable = true;
@@ -215,7 +211,7 @@ public:
{
auto const& s = random_string();
ws.binary(true);
w.write(ws, buffer(s));
w.write(ws, net::buffer(s));
flat_buffer b;
w.read(ws, b);
BEAST_EXPECT(buffers_to_string(b.data()) == s);
@@ -230,8 +226,8 @@ public:
// This call should produce no
// output due to compression latency.
w.write_some(ws, false,
buffer(s.data(), chop));
w.write_some(ws, true, buffer(
net::buffer(s.data(), chop));
w.write_some(ws, true, net::buffer(
s.data() + chop, s.size() - chop));
flat_buffer b;
w.read(ws, b);
@@ -244,7 +240,7 @@ public:
{
auto const& s = random_string();
ws.binary(true);
w.write(ws, buffer(s));
w.write(ws, net::buffer(s));
flat_buffer b;
w.read(ws, b);
BEAST_EXPECT(buffers_to_string(b.data()) == s);
@@ -254,8 +250,6 @@ public:
void
testWrite()
{
using net::buffer;
doTestWrite<false>(SyncClient{});
doTestWrite<true>(SyncClient{});
doTestWriteDeflate(SyncClient{});
@@ -271,8 +265,6 @@ public:
void
testWriteSuspend()
{
using net::buffer;
// suspend on ping
doFailLoop([&](test::fail_count& fc)
{
@@ -392,7 +384,7 @@ public:
std::size_t count = 0;
std::string const s(16384, '*');
ws.auto_fragment(false);
ws.async_write(buffer(s),
ws.async_write(net::buffer(s),
[&](error_code ec, std::size_t n)
{
++count;
@@ -426,7 +418,7 @@ public:
std::size_t count = 0;
std::string const s(16384, '*');
ws.auto_fragment(true);
ws.async_write(buffer(s),
ws.async_write(net::buffer(s),
[&](error_code ec, std::size_t n)
{
++count;
@@ -459,7 +451,7 @@ public:
std::size_t count = 0;
std::string const s(16384, '*');
ws.auto_fragment(false);
ws.async_write(buffer(s),
ws.async_write(net::buffer(s),
[&](error_code ec, std::size_t n)
{
++count;
@@ -491,7 +483,7 @@ public:
std::size_t count = 0;
std::string const s(16384, '*');
ws.auto_fragment(true);
ws.async_write(buffer(s),
ws.async_write(net::buffer(s),
[&](error_code ec, std::size_t n)
{
++count;
@@ -529,7 +521,7 @@ public:
std::size_t count = 0;
auto const& s = random_string();
ws.binary(true);
ws.async_write(buffer(s),
ws.async_write(net::buffer(s),
[&](error_code ec, std::size_t n)
{
++count;
+1 -1
View File
@@ -12,6 +12,7 @@
#include "test/beast/http/message_fuzz.hpp"
#include <boost/beast/http.hpp>
#include <boost/beast/core/buffer_size.hpp>
#include <boost/beast/core/buffers_suffix.hpp>
#include <boost/beast/core/buffers_to_string.hpp>
#include <boost/beast/core/ostream.hpp>
@@ -76,7 +77,6 @@ public:
basic_parser<isRequest, Derived>& parser,
error_code& ec)
{
using net::buffer_size;
beast::buffers_suffix<
ConstBufferSequence> cb{buffers};
std::size_t used = 0;
+4 -5
View File
@@ -115,7 +115,7 @@ class connection
test_buffer const& tb_;
net::strand<
net::io_context::executor_type> strand_;
boost::beast::multi_buffer buffer_;
beast::multi_buffer buffer_;
std::mt19937_64 rng_;
std::size_t count_ = 0;
std::size_t bytes_ = 0;
@@ -187,11 +187,10 @@ private:
void
do_write()
{
using net::buffer_size;
std::geometric_distribution<std::size_t> dist{
double(4) / buffer_size(tb_)};
double(4) / beast::buffer_size(tb_)};
ws_.async_write_some(true,
boost::beast::buffers_prefix(dist(rng_), tb_),
beast::buffers_prefix(dist(rng_), tb_),
alloc_.wrap(std::bind(
&connection::on_write,
shared_from_this(),
@@ -281,7 +280,7 @@ throughput(
int
main(int argc, char** argv)
{
boost::beast::unit_test::dstream dout(std::cerr);
beast::unit_test::dstream dout(std::cerr);
try
{
+1 -2
View File
@@ -95,8 +95,7 @@ std::string string_from_buffers (ConstBufferSequence const& buffers)
// optimization: reserve all the space for the string first
std::string result;
using net::buffer_size; // buffer_size is a customization point,
result.reserve(buffer_size(buffers)); // called without namespace qualification
result.reserve(beast::buffer_size(buffers)); // beast version of net::buffer_size
// iterate over each buffer in the sequence and append it to the string
for(auto it = net::buffer_sequence_begin(buffers); // returns an iterator to beginning of the sequence
+1 -1
View File
@@ -7,6 +7,7 @@
// Official repository: https://github.com/boostorg/beast
//
#include <boost/beast/core/buffer_size.hpp>
#include <boost/beast/core/error.hpp>
#include <boost/beast/core/file_base.hpp>
#include <boost/beast/http/message.hpp>
@@ -164,7 +165,6 @@ struct BodyReader
// The specification requires this to indicate "no error"
ec = {};
using net::buffer_size;
return buffer_size(buffers);
}
-5
View File
@@ -272,7 +272,6 @@ void fxx() {
auto const cb3 = get_next_chunk_body();
// Manually emit a chunk by first writing the chunk-size header with the correct size
using net::buffer_size;
net::write(sock, chunk_header{
buffer_size(cb1) +
buffer_size(cb2) +
@@ -368,7 +367,6 @@ print_cxx14(message<isRequest, Body, Fields> const& m)
{
ec = {};
std::cout << buffers(buffer);
using net::buffer_size;
sr.consume(buffer_size(buffer));
});
}
@@ -396,7 +394,6 @@ struct lambda
{
ec = {};
std::cout << buffers(buffer);
using net::buffer_size;
sr.consume(buffer_size(buffer));
}
};
@@ -438,7 +435,6 @@ split_print_cxx14(message<isRequest, Body, Fields> const& m)
{
ec = {};
std::cout << buffers(buffer);
using net::buffer_size;
sr.consume(buffer_size(buffer));
});
}
@@ -453,7 +449,6 @@ split_print_cxx14(message<isRequest, Body, Fields> const& m)
{
ec = {};
std::cout << buffers(buffer);
using net::buffer_size;
sr.consume(buffer_size(buffer));
});
}
-1
View File
@@ -202,7 +202,6 @@ boost::ignore_unused(ec);
// This will cause the message to be broken up into multiple frames.
for(;;)
{
using net::buffer_size;
if(buffer_size(cb) > 512)
{
// There are more than 512 bytes left to send, just