mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Beast.Asio:
New classes:
class async_completion:
Helper class for implementing asynchronous initiation functions.
See n3964:
Library Foundations for Asynchronous Operations, Revision 1
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3964.pdf
class basic_streambuf:
Meets the requirements of Streambuf.
class buffered_readstream:
Buffers a ReadStream with a ConstBufferSequence.
class consuming_buffers:
Adapts a BufferSequence which wraps the underlying buffer
sequence and presents fewer bytes, with the retained bytes
occurring at the end of the sequence.
class handler_alloc:
A C++ Allocator the uses asio handler allocation hooks.
class static_streambuf:
An implementation of the Streambuf concept that uses a
fixed size buffer with size determined at compile-time.
class streambuf_readstream:
Buffers a ReadStream with a Streambuf.
New functions:
append_buffers()
Returns a new BufferSequence which efficiently concatenates
two or more buffer sequences together.
prepare_buffers()
Shortens a buffer sequence. The bytes excluded are at the
end of the underlying buffer sequence.
boost::asio::read_until()
A copy of boost::asio::read_until overloads, modified to work
with a beast::asio::basic_streambuf.
Debugging:
buffers_to_string()
Convert a ConstBufferSequence to a human readable string
suitable for diagnostics.
type_check.h:
Metafunctions for checking asio concepts:
AsyncReadStream, AsyncWriteStream
SyncReadStream, SyncWriteStream
ConstBufferSequence, MutableBufferSequence
Streambuf
Handler
Changes:
* All symbols moved up a namespace level.
* streambuf provides all move and copy special members,
behavior of moved from objects is well-defined.
Fixes:
* Fix basic_streambuf iterator category.
This commit is contained in:
103
test/asio/prepare_buffers.cpp
Normal file
103
test/asio/prepare_buffers.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 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)
|
||||
//
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include <beast/asio/prepare_buffers.h>
|
||||
|
||||
#include <beast/asio/consuming_buffers.h>
|
||||
#include <beast/unit_test/suite.h>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace beast {
|
||||
namespace asio {
|
||||
namespace test {
|
||||
|
||||
class prepare_buffers_test : public unit_test::suite
|
||||
{
|
||||
public:
|
||||
template<class ConstBufferSequence>
|
||||
static
|
||||
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(auto const& b : bs)
|
||||
s.append(buffer_cast<char const*>(b),
|
||||
buffer_size(b));
|
||||
return s;
|
||||
}
|
||||
|
||||
void testBuffers()
|
||||
{
|
||||
using boost::asio::buffer_size;
|
||||
using boost::asio::const_buffer;
|
||||
std::string const s = "Hello, world";
|
||||
expect(s.size() == 12);
|
||||
for(std::size_t x = 1; x < 4; ++x) {
|
||||
for(std::size_t y = 1; y < 4; ++y) {
|
||||
std::size_t z = s.size() - (x + y);
|
||||
{
|
||||
std::array<const_buffer, 3> bs{{
|
||||
const_buffer{&s[0], x},
|
||||
const_buffer{&s[x], y},
|
||||
const_buffer{&s[x+y], z}}};
|
||||
for(std::size_t i = 0; i <= s.size() + 1; ++i)
|
||||
{
|
||||
auto pb = prepare_buffers(i, bs);
|
||||
expect(to_string(pb) == s.substr(0, i));
|
||||
auto pb2 = pb;
|
||||
expect(to_string(pb2) == to_string(pb));
|
||||
pb = prepare_buffers(0, bs);
|
||||
pb2 = pb;
|
||||
expect(buffer_size(pb2) == 0);
|
||||
pb2 = prepare_buffers(i, bs);
|
||||
expect(to_string(pb2) == s.substr(0, i));
|
||||
}
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
void testNullBuffers()
|
||||
{
|
||||
using boost::asio::buffer_copy;
|
||||
using boost::asio::buffer_size;
|
||||
using boost::asio::null_buffers;
|
||||
auto pb0 = prepare_buffers(0, null_buffers{});
|
||||
expect(buffer_size(pb0) == 0);
|
||||
auto pb1 = prepare_buffers(1, null_buffers{});
|
||||
expect(buffer_size(pb1) == 0);
|
||||
expect(buffer_copy(pb0, pb1) == 0);
|
||||
|
||||
using pb_type = decltype(pb0);
|
||||
consuming_buffers<pb_type> cb(pb0);
|
||||
expect(buffer_size(cb) == 0);
|
||||
expect(buffer_copy(cb, pb1) == 0);
|
||||
cb.consume(1);
|
||||
expect(buffer_size(cb) == 0);
|
||||
expect(buffer_copy(cb, pb1) == 0);
|
||||
|
||||
auto pbc = prepare_buffers(2, cb);
|
||||
expect(buffer_size(pbc) == 0);
|
||||
expect(buffer_copy(pbc, cb) == 0);
|
||||
}
|
||||
|
||||
void run() override
|
||||
{
|
||||
testBuffers();
|
||||
testNullBuffers();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(prepare_buffers,asio,beast);
|
||||
|
||||
} // test
|
||||
} // asio
|
||||
} // beast
|
||||
Reference in New Issue
Block a user