0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 12:12:15 +02:00

buffer.hpp changes:

* added const_buffers_1_limit() method that is like
  const_buffers_1_clamp() but includes an upper-bound size
  constraint.

* realign() should be a no-op if headroom == offset_

* added additional reset() convenience method that also calls
  init_headroom()
This commit is contained in:
James Yonan 2015-10-28 22:33:26 -06:00
parent 03dcf82004
commit 79fdea43d2

View File

@ -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<T>::init_headroom(headroom);
}
void move(BufferAllocatedType& other)
{
if (data_)