drain_buffer is removed (API Change):

* The drain_buffer dynamic buffer is no longer a public interface.

Actions Required:

* Replace code which uses drain_buffer. For websocket::stream,
  it is no longer necessary to manually drain the connection
  after closing.
This commit is contained in:
Vinnie Falco
2017-08-03 19:22:35 -07:00
parent 64327739f0
commit de03a1a32d
11 changed files with 6 additions and 209 deletions

View File

@ -21,11 +21,17 @@ API Changes:
* Calls to stream::close and stream::async_close will
automatically perform the required read operations
* drain_buffer is removed
Actions Required:
* Remove calling code which drains the connection after
calling stream::close or stream::async_close
* Replace code which uses drain_buffer. For websocket::stream,
it is no longer necessary to manually drain the connection
after closing.
--------------------------------------------------------------------------------
Version 99:

View File

@ -50,15 +50,6 @@ of scenarios:
output areas equal to the size of the underlying mutable buffer sequence.
The implementation does not perform heap allocations.
]]
[[
[link beast.ref.boost__beast__drain_buffer `drain_buffer`]
][
A drain buffer has a small internal buffer and maximum size that
uses no dynamic allocation. It always has a size of zero, and
silently discards its input. This buffer may be passed to functions
which store data in a dynamic buffer when the caller wishes to
efficiently discard the data.
]]
[[
[link beast.ref.boost__beast__flat_buffer `flat_buffer`]
[link beast.ref.boost__beast__basic_flat_buffer `basic_flat_buffer`]

View File

@ -126,7 +126,6 @@ implementation strategies:
* [link beast.ref.boost__beast__basic_flat_buffer `basic_flat_buffer`]
* [link beast.ref.boost__beast__basic_multi_buffer `basic_multi_buffer`]
* [link beast.ref.boost__beast__drain_buffer `drain_buffer`]
* [link beast.ref.boost__beast__flat_buffer `flat_buffer`]
* [link beast.ref.boost__beast__flat_static_buffer `flat_static_buffer`]
* [link beast.ref.boost__beast__flat_static_buffer_base `flat_static_buffer_base`]

View File

@ -183,7 +183,6 @@
<member><link linkend="beast.ref.boost__beast__buffered_read_stream">buffered_read_stream</link></member>
<member><link linkend="beast.ref.boost__beast__buffers_adapter">buffers_adapter</link></member>
<member><link linkend="beast.ref.boost__beast__consuming_buffers">consuming_buffers</link></member>
<member><link linkend="beast.ref.boost__beast__drain_buffer">drain_buffer</link></member>
<member><link linkend="beast.ref.boost__beast__file">file</link></member>
<member><link linkend="beast.ref.boost__beast__file_mode">file_mode</link></member>
<member><link linkend="beast.ref.boost__beast__file_posix">file_posix</link></member>

View File

@ -19,7 +19,6 @@
#include <boost/beast/core/buffered_read_stream.hpp>
#include <boost/beast/core/buffers_adapter.hpp>
#include <boost/beast/core/consuming_buffers.hpp>
#include <boost/beast/core/drain_buffer.hpp>
#include <boost/beast/core/error.hpp>
#include <boost/beast/core/file.hpp>
#include <boost/beast/core/file_base.hpp>

View File

@ -1,127 +0,0 @@
//
// Copyright (c) 2016-2017 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)
//
// Official repository: https://github.com/boostorg/beast
//
#ifndef BOOST_BEAST_DRAIN_BUFFER_HPP
#define BOOST_BEAST_DRAIN_BUFFER_HPP
#include <boost/beast/config.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/throw_exception.hpp>
namespace boost {
namespace beast {
/** A @b DynamicBuffer which does not retain its input sequence.
This object implements a dynamic buffer with a fixed size
output area, not dynamically allocated, and whose input
sequence is always length zero. Bytes committed from the
output area to the input area are always discarded. This
is useful for calling interfaces that require a dynamic
buffer for storage, but where the caller does not want
to retain the data.
*/
class drain_buffer
{
char buf_[512];
std::size_t n_ = 0;
public:
/// The type used to represent the input sequence as a list of buffers.
using const_buffers_type = boost::asio::null_buffers;
/// The type used to represent the output sequence as a list of buffers.
using mutable_buffers_type = boost::asio::mutable_buffers_1;
/// Constructor
drain_buffer() = default;
/// Copy constructor
drain_buffer(drain_buffer const&)
{
// Previously returned ranges are invalidated
}
/// Copy assignment
drain_buffer&
operator=(drain_buffer const&)
{
n_ = 0;
return *this;
}
/// Return the size of the input sequence.
std::size_t
size() const
{
return 0;
}
/// Return the maximum sum of the input and output sequence sizes.
std::size_t
max_size() const
{
return sizeof(buf_);
}
/// Return the maximum sum of input and output sizes that can be held without an allocation.
std::size_t
capacity() const
{
return max_size();
}
/** Get a list of buffers that represent the input sequence.
@note These buffers remain valid across subsequent calls to `prepare`.
*/
const_buffers_type
data() const
{
return {};
}
/** Get a list of buffers that represent the output sequence, with the given size.
@throws std::length_error if the size would exceed the buffer limit
*/
mutable_buffers_type
prepare(std::size_t n)
{
if(n > sizeof(buf_))
BOOST_THROW_EXCEPTION(std::length_error{
"buffer overflow"});
n_ = n;
return {buf_, n_};
}
/** Move bytes from the output sequence to the input sequence.
This call always discards the output sequence.
The size of the input sequence will remain at zero.
*/
void
commit(std::size_t)
{
}
/** Remove bytes from the input sequence.
This call has no effect.
*/
void
consume(std::size_t)
{
}
};
} // beast
} // boost
#endif

View File

@ -26,7 +26,6 @@ add_executable (tests-beast-core
buffers_adapter.cpp
clamp.cpp
consuming_buffers.cpp
drain_buffer.cpp
error.cpp
file.cpp
file_posix.cpp

View File

@ -16,7 +16,6 @@ local SOURCES =
buffers_adapter.cpp
clamp.cpp
consuming_buffers.cpp
drain_buffer.cpp
error.cpp
file.cpp
file_posix.cpp

View File

@ -1,55 +0,0 @@
//
// Copyright (c) 2016-2017 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)
//
// Official repository: https://github.com/boostorg/beast
//
// Test that header file is self-contained.
#include <boost/beast/core/drain_buffer.hpp>
#include <boost/beast/core/type_traits.hpp>
#include <boost/beast/unit_test/suite.hpp>
namespace boost {
namespace beast {
static_assert(is_dynamic_buffer<drain_buffer>::value,
"DynamicBuffer requirements not met");
class drain_buffer_test : public beast::unit_test::suite
{
public:
void
run() override
{
using boost::asio::buffer_size;
drain_buffer b;
BEAST_EXPECT(buffer_size(b.prepare(0)) == 0);
BEAST_EXPECT(buffer_size(b.prepare(100)) == 100);
try
{
b.prepare(b.max_size() + 1);
fail("", __FILE__, __LINE__);
}
catch(std::length_error const&)
{
pass();
}
b.prepare(10);
BEAST_EXPECT(b.size() == 0);
b.commit(10);
BEAST_EXPECT(b.size() == 0);
b.consume(10);
BEAST_EXPECT(b.size() == 0);
b.consume(1000);
BEAST_EXPECT(b.size() == 0);
}
};
BEAST_DEFINE_TESTSUITE(beast,core,drain_buffer);
} // beast
} // boost

View File

@ -10,7 +10,6 @@
// Test that header file is self-contained.
#include <boost/beast/core/read_size.hpp>
#include <boost/beast/core/drain_buffer.hpp>
#include <boost/beast/core/flat_buffer.hpp>
#include <boost/beast/core/flat_static_buffer.hpp>
#include <boost/beast/core/multi_buffer.hpp>
@ -37,7 +36,6 @@ public:
void
run() override
{
check<drain_buffer>();
check<flat_buffer>();
check<flat_static_buffer<1024>>();
check<multi_buffer>();

View File

@ -20,7 +20,6 @@
# include "example/server-framework/wss_ports.hpp"
#endif
#include <boost/beast/core/drain_buffer.hpp>
#include <boost/beast/websocket.hpp>
#include <boost/beast/test/yield_to.hpp>
#include <boost/beast/unit_test/suite.hpp>
@ -107,16 +106,6 @@ public:
ws.close(beast::websocket::close_code::normal, ec);
if(! BEAST_EXPECTS(! ec, ec.message()))
return;
// VFALCO Verify the buffer's contents
drain_buffer drain;
for(;;)
{
ws.read(drain, ec);
if(ec == beast::websocket::error::closed)
break;
if(! BEAST_EXPECTS(! ec, ec.message()))
return;
}
}
void