9be88fb192
This change adds a new set of type requirements for dynamic buffers, DynamicBuffer_v2, which supports copy construction. These new type requirements enable dynamic buffers to be used as arguments to user-defined composed operations, where the same dynamic buffer object is used repeatedly for multiple underlying operations. For example: template <typename DynamicBuffer> void echo_line(tcp::socket& sock, DynamicBuffer buf) { n = boost::asio::read_until(sock, buf, '\n'); boost::asio::write(sock, buf, boost::asio::transfer_exactly(n)); } The original DynamicBuffer type requirements have been renamed to DynamicBuffer_v1. New type traits is_dynamic_buffer_v1 and is_dynamic_buffer_v2 have been added to test for conformance to DynamicBuffer_v1 and DynamicBuffer_v2 respectively. The existing is_dynamic_buffer trait has been retained and delegates to is_dynamic_buffer_v1, unless BOOST_ASIO_NO_DYNAMIC_BUFFER_V1 is defined, in which case it delegates to is_dynamic_buffer_v2. The dynamic_string_buffer and dynamic_vector buffer classes conform to both DynamicBuffer_v1 and DynamicBuffer_v2 requirements. When BOOST_ASIO_NO_DYNAMIC_BUFFER_V1 is defined, all support for DynamicBuffer_v1 types and functions is #ifdef-ed out. Support for using basic_streambuf with the read, async_read, read_until, async_read_until, write, and async_write functions is also disabled as a consequence. This change should have no impact on existing source code that simply uses dynamic buffers in conjunction with asio's composed operations, such as: string data; // ... size_t n = boost::asio::read_until(my_socket boost::asio::dynamic_buffer(data, MY_MAX), '\n');
94 lines
3.5 KiB
Plaintext
94 lines
3.5 KiB
Plaintext
[/
|
|
/ Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff 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)
|
|
/]
|
|
|
|
[section:DynamicBuffer_v1 Dynamic buffer requirements (version 1)]
|
|
|
|
A dynamic buffer encapsulates memory storage that may be automatically resized
|
|
as required, where the memory is divided into an input sequence followed by an
|
|
output sequence. These memory regions are internal to the dynamic buffer
|
|
sequence, but direct access to the elements is provided to permit them to be
|
|
efficiently used with I/O operations, such as the `send` or `receive`
|
|
operations of a socket. Data written to the output sequence of a dynamic buffer
|
|
sequence object is appended to the input sequence of the same object.
|
|
|
|
A dynamic buffer type `X` shall satisfy the requirements of `MoveConstructible`
|
|
(C++ Std, [moveconstructible]) types in addition to those listed below.
|
|
|
|
In the table below, `X` denotes a dynamic buffer class, `x` denotes a
|
|
value of type `X&`, `x1` denotes values of type `const X&`, and `n` denotes a
|
|
value of type `size_t`, and `u` denotes an identifier.
|
|
|
|
[table DynamicBuffer_v1 requirements
|
|
[[expression] [type] [assertion/note\npre/post-conditions]]
|
|
[
|
|
[`X::const_buffers_type`]
|
|
[type meeting [link boost_asio.reference.ConstBufferSequence ConstBufferSequence]
|
|
requirements.]
|
|
[This type represents the memory associated with the input sequence.]
|
|
]
|
|
[
|
|
[`X::mutable_buffers_type`]
|
|
[type meeting [link boost_asio.reference.MutableBufferSequence MutableBufferSequence]
|
|
requirements.]
|
|
[This type represents the memory associated with the output sequence.]
|
|
]
|
|
[
|
|
[`x1.size()`]
|
|
[`size_t`]
|
|
[Returns the size, in bytes, of the input sequence.]
|
|
]
|
|
[
|
|
[`x1.max_size()`]
|
|
[`size_t`]
|
|
[Returns the permitted maximum of the sum of the sizes of the input
|
|
sequence and output sequence.]
|
|
]
|
|
[
|
|
[`x1.capacity()`]
|
|
[`size_t`]
|
|
[Returns the maximum sum of the sizes of the input sequence and output
|
|
sequence that the dynamic buffer can hold without requiring reallocation.]
|
|
]
|
|
[
|
|
[`x1.data()`]
|
|
[`X::const_buffers_type`]
|
|
[Returns a constant buffer sequence `u` that represents the memory
|
|
associated with the input sequence, and where `buffer_size(u) == size()`.]
|
|
]
|
|
[
|
|
[`x.prepare(n)`]
|
|
[`X::mutable_buffers_type`]
|
|
[Requires: `size() + n <= max_size()`.\n
|
|
\n
|
|
Returns a mutable buffer sequence `u` representing the output sequence, and
|
|
where `buffer_size(u) == n`. The dynamic buffer reallocates memory as
|
|
required. All constant or mutable buffer sequences previously obtained
|
|
using `data()` or `prepare()` are invalidated.\n
|
|
\n
|
|
Throws: `length_error` if `size() + n > max_size()`.]
|
|
]
|
|
[
|
|
[`x.commit(n)`]
|
|
[]
|
|
[Appends `n` bytes from the start of the output sequence to the end of the
|
|
input sequence. The remainder of the output sequence is discarded. If `n`
|
|
is greater than the size of the output sequence, the entire output sequence
|
|
is appended to the input sequence. All constant or mutable buffer sequences
|
|
previously obtained using `data()` or `prepare()` are invalidated.]
|
|
]
|
|
[
|
|
[`x.consume(n)`]
|
|
[]
|
|
[Removes `n` bytes from beginning of the input sequence. If `n` is greater
|
|
than the size of the input sequence, the entire input sequence is removed.
|
|
All constant or mutable buffer sequences previously obtained using `data()`
|
|
or `prepare()` are invalidated.]
|
|
]
|
|
]
|
|
|
|
[endsect]
|