Dynamic buffer input areas are mutable

This commit is contained in:
Vinnie Falco
2017-08-14 15:29:33 -07:00
parent d337339c02
commit 3fe6cef129
7 changed files with 45 additions and 26 deletions

View File

@ -1,3 +1,9 @@
Version 106:
* Dynamic buffer input areas are mutable
--------------------------------------------------------------------------------
Version 105: Version 105:
* Fix compile error in websocket snippet * Fix compile error in websocket snippet

View File

@ -84,7 +84,7 @@ public:
using allocator_type = Allocator; using allocator_type = Allocator;
/// The type used to represent the input sequence as a list of buffers. /// The type used to represent the input sequence as a list of buffers.
using const_buffers_type = boost::asio::const_buffers_1; using const_buffers_type = boost::asio::mutable_buffers_1;
/// The type used to represent the output sequence as a list of buffers. /// The type used to represent the output sequence as a list of buffers.
using mutable_buffers_type = boost::asio::mutable_buffers_1; using mutable_buffers_type = boost::asio::mutable_buffers_1;

View File

@ -52,7 +52,7 @@ public:
This buffer sequence is guaranteed to have length 1. This buffer sequence is guaranteed to have length 1.
*/ */
using const_buffers_type = boost::asio::const_buffers_1; using const_buffers_type = boost::asio::mutable_buffers_1;
/** The type used to represent the mutable input sequence as a list of buffers. /** The type used to represent the mutable input sequence as a list of buffers.

View File

@ -17,7 +17,6 @@
#include <cstring> #include <cstring>
#include <iterator> #include <iterator>
#include <stdexcept> #include <stdexcept>
#include <type_traits>
namespace boost { namespace boost {
namespace beast { namespace beast {
@ -29,7 +28,7 @@ class buffers_adapter<MutableBufferSequence>::
buffers_adapter const* ba_; buffers_adapter const* ba_;
public: public:
using value_type = boost::asio::const_buffer; using value_type = boost::asio::mutable_buffer;
class const_iterator; class const_iterator;

View File

@ -132,8 +132,7 @@ class basic_multi_buffer<Allocator>::const_buffers_type
const_buffers_type(basic_multi_buffer const& b); const_buffers_type(basic_multi_buffer const& b);
public: public:
// Why? using value_type = boost::asio::mutable_buffer;
using value_type = boost::asio::const_buffer;
class const_iterator; class const_iterator;

View File

@ -35,14 +35,19 @@ static_buffer_base::
data() const -> data() const ->
const_buffers_type const_buffers_type
{ {
using boost::asio::const_buffer; using boost::asio::mutable_buffer;
const_buffers_type result;
if(in_off_ + in_size_ <= capacity_) if(in_off_ + in_size_ <= capacity_)
return {{ {
{const_buffer{begin_ + in_off_, in_size_}}, result[0] = mutable_buffer{begin_ + in_off_, in_size_};
{const_buffer{begin_, 0}}}}; result[1] = mutable_buffer{begin_, 0};
return {{ }
{const_buffer{begin_ + in_off_, capacity_ - in_off_}}, else
{const_buffer{begin_, in_size_ - (capacity_ - in_off_)}}}}; {
result[0] = mutable_buffer{begin_ + in_off_, capacity_ - in_off_};
result[1] = mutable_buffer{begin_, in_size_ - (capacity_ - in_off_)};
}
return result;
} }
inline inline
@ -52,13 +57,18 @@ mutable_data() ->
mutable_data_type mutable_data_type
{ {
using boost::asio::mutable_buffer; using boost::asio::mutable_buffer;
mutable_data_type result;
if(in_off_ + in_size_ <= capacity_) if(in_off_ + in_size_ <= capacity_)
return {{ {
{mutable_buffer{begin_ + in_off_, in_size_}}, result[0] = mutable_buffer{begin_ + in_off_, in_size_};
{mutable_buffer{begin_, 0}}}}; result[1] = mutable_buffer{begin_, 0};
return {{ }
{mutable_buffer{begin_ + in_off_, capacity_ - in_off_}}, else
{mutable_buffer{begin_, in_size_ - (capacity_ - in_off_)}}}}; {
result[0] = mutable_buffer{begin_ + in_off_, capacity_ - in_off_};
result[1] = mutable_buffer{begin_, in_size_ - (capacity_ - in_off_)};
}
return result;
} }
inline inline
@ -73,13 +83,18 @@ prepare(std::size_t size) ->
"buffer overflow"}); "buffer overflow"});
out_size_ = size; out_size_ = size;
auto const out_off = (in_off_ + in_size_) % capacity_; auto const out_off = (in_off_ + in_size_) % capacity_;
mutable_buffers_type result;
if(out_off + out_size_ <= capacity_ ) if(out_off + out_size_ <= capacity_ )
return {{ {
{mutable_buffer{begin_ + out_off, out_size_}}, result[0] = mutable_buffer{begin_ + out_off, out_size_};
{mutable_buffer{begin_, 0}}}}; result[1] = mutable_buffer{begin_, 0};
return {{ }
{mutable_buffer{begin_ + out_off, capacity_ - out_off}}, else
{mutable_buffer{begin_, out_size_ - (capacity_ - out_off)}}}}; {
result[0] = mutable_buffer{begin_ + out_off, capacity_ - out_off};
result[1] = mutable_buffer{begin_, out_size_ - (capacity_ - out_off)};
}
return result;
} }
inline inline

View File

@ -52,7 +52,7 @@ class static_buffer_base
public: public:
/// The type used to represent the input sequence as a list of buffers. /// The type used to represent the input sequence as a list of buffers.
using const_buffers_type = using const_buffers_type =
std::array<boost::asio::const_buffer, 2>; std::array<boost::asio::mutable_buffer, 2>;
/// The type used to represent the mutable input sequence as a list of buffers. /// The type used to represent the mutable input sequence as a list of buffers.
using mutable_data_type = using mutable_data_type =