diff --git a/openvpn/buffer/buffer.hpp b/openvpn/buffer/buffer.hpp index a55485e2..9042c531 100644 --- a/openvpn/buffer/buffer.hpp +++ b/openvpn/buffer/buffer.hpp @@ -410,14 +410,22 @@ namespace openvpn { { return asio::const_buffers_1(c_data(), buf_clamp_write(size())); } + + asio::const_buffers_1 const_buffers_1_limit(const size_t limit) const + { + return asio::const_buffers_1(c_data(), std::min(buf_clamp_write(size()), limit)); + } #endif void realign(size_t headroom) { - if (headroom + size_ > capacity_) - OPENVPN_BUFFER_THROW(buffer_headroom); - std::memmove(data_ + headroom, data_ + offset_, size_); - offset_ = headroom; + if (headroom != offset_) + { + if (headroom + size_ > capacity_) + OPENVPN_BUFFER_THROW(buffer_headroom); + std::memmove(data_ + headroom, data_ + offset_, size_); + offset_ = headroom; + } } void write(const T* data, const size_t size) @@ -475,6 +483,12 @@ namespace openvpn { reset_impl(min_capacity, flags); } + void reset(const size_t headroom, const size_t min_capacity, const unsigned int flags) + { + reset(min_capacity, flags); + init_headroom(headroom); + } + void append(const BufferType& other) { write(other.c_data(), other.size()); @@ -668,6 +682,12 @@ namespace openvpn { init (min_capacity, flags); } + void reset(const size_t headroom, const size_t min_capacity, const unsigned int flags) + { + reset(min_capacity, flags); + BufferType::init_headroom(headroom); + } + void move(BufferAllocatedType& other) { if (data_)