mirror of
https://github.com/boostorg/beast.git
synced 2025-07-31 05:17:26 +02:00
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:
@ -21,11 +21,17 @@ API Changes:
|
|||||||
* Calls to stream::close and stream::async_close will
|
* Calls to stream::close and stream::async_close will
|
||||||
automatically perform the required read operations
|
automatically perform the required read operations
|
||||||
|
|
||||||
|
* drain_buffer is removed
|
||||||
|
|
||||||
Actions Required:
|
Actions Required:
|
||||||
|
|
||||||
* Remove calling code which drains the connection after
|
* Remove calling code which drains the connection after
|
||||||
calling stream::close or stream::async_close
|
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:
|
Version 99:
|
||||||
|
@ -50,15 +50,6 @@ of scenarios:
|
|||||||
output areas equal to the size of the underlying mutable buffer sequence.
|
output areas equal to the size of the underlying mutable buffer sequence.
|
||||||
The implementation does not perform heap allocations.
|
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__flat_buffer `flat_buffer`]
|
||||||
[link beast.ref.boost__beast__basic_flat_buffer `basic_flat_buffer`]
|
[link beast.ref.boost__beast__basic_flat_buffer `basic_flat_buffer`]
|
||||||
|
@ -126,7 +126,6 @@ implementation strategies:
|
|||||||
|
|
||||||
* [link beast.ref.boost__beast__basic_flat_buffer `basic_flat_buffer`]
|
* [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__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_buffer `flat_buffer`]
|
||||||
* [link beast.ref.boost__beast__flat_static_buffer `flat_static_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`]
|
* [link beast.ref.boost__beast__flat_static_buffer_base `flat_static_buffer_base`]
|
||||||
|
@ -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__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__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__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">file</link></member>
|
||||||
<member><link linkend="beast.ref.boost__beast__file_mode">file_mode</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>
|
<member><link linkend="beast.ref.boost__beast__file_posix">file_posix</link></member>
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
#include <boost/beast/core/buffered_read_stream.hpp>
|
#include <boost/beast/core/buffered_read_stream.hpp>
|
||||||
#include <boost/beast/core/buffers_adapter.hpp>
|
#include <boost/beast/core/buffers_adapter.hpp>
|
||||||
#include <boost/beast/core/consuming_buffers.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/error.hpp>
|
||||||
#include <boost/beast/core/file.hpp>
|
#include <boost/beast/core/file.hpp>
|
||||||
#include <boost/beast/core/file_base.hpp>
|
#include <boost/beast/core/file_base.hpp>
|
||||||
|
@ -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
|
|
@ -26,7 +26,6 @@ add_executable (tests-beast-core
|
|||||||
buffers_adapter.cpp
|
buffers_adapter.cpp
|
||||||
clamp.cpp
|
clamp.cpp
|
||||||
consuming_buffers.cpp
|
consuming_buffers.cpp
|
||||||
drain_buffer.cpp
|
|
||||||
error.cpp
|
error.cpp
|
||||||
file.cpp
|
file.cpp
|
||||||
file_posix.cpp
|
file_posix.cpp
|
||||||
|
@ -16,7 +16,6 @@ local SOURCES =
|
|||||||
buffers_adapter.cpp
|
buffers_adapter.cpp
|
||||||
clamp.cpp
|
clamp.cpp
|
||||||
consuming_buffers.cpp
|
consuming_buffers.cpp
|
||||||
drain_buffer.cpp
|
|
||||||
error.cpp
|
error.cpp
|
||||||
file.cpp
|
file.cpp
|
||||||
file_posix.cpp
|
file_posix.cpp
|
||||||
|
@ -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
|
|
@ -10,7 +10,6 @@
|
|||||||
// Test that header file is self-contained.
|
// Test that header file is self-contained.
|
||||||
#include <boost/beast/core/read_size.hpp>
|
#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_buffer.hpp>
|
||||||
#include <boost/beast/core/flat_static_buffer.hpp>
|
#include <boost/beast/core/flat_static_buffer.hpp>
|
||||||
#include <boost/beast/core/multi_buffer.hpp>
|
#include <boost/beast/core/multi_buffer.hpp>
|
||||||
@ -37,7 +36,6 @@ public:
|
|||||||
void
|
void
|
||||||
run() override
|
run() override
|
||||||
{
|
{
|
||||||
check<drain_buffer>();
|
|
||||||
check<flat_buffer>();
|
check<flat_buffer>();
|
||||||
check<flat_static_buffer<1024>>();
|
check<flat_static_buffer<1024>>();
|
||||||
check<multi_buffer>();
|
check<multi_buffer>();
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
# include "example/server-framework/wss_ports.hpp"
|
# include "example/server-framework/wss_ports.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <boost/beast/core/drain_buffer.hpp>
|
|
||||||
#include <boost/beast/websocket.hpp>
|
#include <boost/beast/websocket.hpp>
|
||||||
#include <boost/beast/test/yield_to.hpp>
|
#include <boost/beast/test/yield_to.hpp>
|
||||||
#include <boost/beast/unit_test/suite.hpp>
|
#include <boost/beast/unit_test/suite.hpp>
|
||||||
@ -107,16 +106,6 @@ public:
|
|||||||
ws.close(beast::websocket::close_code::normal, ec);
|
ws.close(beast::websocket::close_code::normal, ec);
|
||||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||||
return;
|
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
|
void
|
||||||
|
Reference in New Issue
Block a user