diff --git a/CHANGELOG.md b/CHANGELOG.md index a9b05060..5fe0f0d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ API Changes: * New buffers() replaces to_string() * Rename to multi_buffer, basic_multi_buffer * Rename to flat_buffer, basic_flat_buffer +* Rename to static_buffer, static_buffer_n -------------------------------------------------------------------------------- diff --git a/doc/quickref.xml b/doc/quickref.xml index 2c4581f8..54806eda 100644 --- a/doc/quickref.xml +++ b/doc/quickref.xml @@ -165,8 +165,8 @@ handler_alloc handler_ptr multi_buffer - static_streambuf - static_streambuf_n + static_buffer + static_buffer_n static_string system_error diff --git a/include/beast/core.hpp b/include/beast/core.hpp index 078ac76a..989db240 100644 --- a/include/beast/core.hpp +++ b/include/beast/core.hpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include diff --git a/include/beast/core/impl/static_streambuf.ipp b/include/beast/core/impl/static_buffer.ipp similarity index 88% rename from include/beast/core/impl/static_streambuf.ipp rename to include/beast/core/impl/static_buffer.ipp index 3ea097e1..8d681f33 100644 --- a/include/beast/core/impl/static_streambuf.ipp +++ b/include/beast/core/impl/static_buffer.ipp @@ -5,8 +5,8 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // -#ifndef BEAST_IMPL_STATIC_STREAMBUF_IPP -#define BEAST_IMPL_STATIC_STREAMBUF_IPP +#ifndef BEAST_IMPL_STATIC_BUFFER_IPP +#define BEAST_IMPL_STATIC_BUFFER_IPP #include #include @@ -17,7 +17,7 @@ namespace beast { -class static_streambuf::const_buffers_type +class static_buffer::const_buffers_type { std::size_t n_; std::uint8_t const* p_; @@ -40,7 +40,7 @@ public: end() const; private: - friend class static_streambuf; + friend class static_buffer; const_buffers_type( std::uint8_t const* p, std::size_t n) @@ -50,7 +50,7 @@ private: } }; -class static_streambuf::const_buffers_type::const_iterator +class static_buffer::const_buffers_type::const_iterator { std::size_t n_ = 0; std::uint8_t const* p_ = nullptr; @@ -133,7 +133,7 @@ private: inline auto -static_streambuf::const_buffers_type::begin() const -> +static_buffer::const_buffers_type::begin() const -> const_iterator { return const_iterator{p_, n_}; @@ -141,7 +141,7 @@ static_streambuf::const_buffers_type::begin() const -> inline auto -static_streambuf::const_buffers_type::end() const -> +static_buffer::const_buffers_type::end() const -> const_iterator { return const_iterator{p_ + n_, n_}; @@ -149,7 +149,7 @@ static_streambuf::const_buffers_type::end() const -> //------------------------------------------------------------------------------ -class static_streambuf::mutable_buffers_type +class static_buffer::mutable_buffers_type { std::size_t n_; std::uint8_t* p_; @@ -172,7 +172,7 @@ public: end() const; private: - friend class static_streambuf; + friend class static_buffer; mutable_buffers_type( std::uint8_t* p, std::size_t n) @@ -182,7 +182,7 @@ private: } }; -class static_streambuf::mutable_buffers_type::const_iterator +class static_buffer::mutable_buffers_type::const_iterator { std::size_t n_ = 0; std::uint8_t* p_ = nullptr; @@ -264,7 +264,7 @@ private: inline auto -static_streambuf::mutable_buffers_type::begin() const -> +static_buffer::mutable_buffers_type::begin() const -> const_iterator { return const_iterator{p_, n_}; @@ -272,7 +272,7 @@ static_streambuf::mutable_buffers_type::begin() const -> inline auto -static_streambuf::mutable_buffers_type::end() const -> +static_buffer::mutable_buffers_type::end() const -> const_iterator { return const_iterator{p_ + n_, n_}; @@ -280,10 +280,9 @@ static_streambuf::mutable_buffers_type::end() const -> //------------------------------------------------------------------------------ - inline auto -static_streambuf::data() const -> +static_buffer::data() const -> const_buffers_type { return const_buffers_type{in_, @@ -292,12 +291,12 @@ static_streambuf::data() const -> inline auto -static_streambuf::prepare(std::size_t n) -> +static_buffer::prepare(std::size_t n) -> mutable_buffers_type { if(n > static_cast(end_ - out_)) throw detail::make_exception( - "no space in static_buffer", __FILE__, __LINE__); + "static_buffer overflow", __FILE__, __LINE__); last_ = out_ + n; return mutable_buffers_type{out_, n}; } diff --git a/include/beast/core/static_streambuf.hpp b/include/beast/core/static_buffer.hpp similarity index 79% rename from include/beast/core/static_streambuf.hpp rename to include/beast/core/static_buffer.hpp index 2a0d49e1..d6dfe58b 100644 --- a/include/beast/core/static_streambuf.hpp +++ b/include/beast/core/static_buffer.hpp @@ -5,8 +5,8 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // -#ifndef BEAST_STATIC_STREAMBUF_HPP -#define BEAST_STATIC_STREAMBUF_HPP +#ifndef BEAST_STATIC_BUFFER_HPP +#define BEAST_STATIC_BUFFER_HPP #include #include @@ -16,17 +16,17 @@ namespace beast { -/** A @b `DynamicBuffer` with a fixed size internal buffer. +/** A @b DynamicBuffer with a fixed size internal buffer. Ownership of the underlying storage belongs to the derived class. @note Variables are usually declared using the template class - @ref static_streambuf_n; however, to reduce the number of instantiations + @ref static_buffer_n; however, to reduce the number of instantiations of template functions receiving static stream buffer arguments in a deduced context, the signature of the receiving function should use - @ref static_streambuf. + @ref static_buffer. */ -class static_streambuf +class static_buffer { #if BEAST_DOXYGEN private: @@ -51,11 +51,11 @@ public: class const_buffers_type; class mutable_buffers_type; - static_streambuf( - static_streambuf const& other) noexcept = delete; + static_buffer( + static_buffer const& other) noexcept = delete; - static_streambuf& operator=( - static_streambuf const&) noexcept = delete; + static_buffer& operator=( + static_buffer const&) noexcept = delete; #endif @@ -121,7 +121,7 @@ private: #else protected: #endif - static_streambuf(std::uint8_t* p, std::size_t n) + static_buffer(std::uint8_t* p, std::size_t n) { reset(p, n); } @@ -139,17 +139,17 @@ protected: //------------------------------------------------------------------------------ -/** A `DynamicBuffer` with a fixed size internal buffer. +/** A @b DynamicBuffer with a fixed size internal buffer. @tparam N The number of bytes in the internal buffer. @note To reduce the number of template instantiations when passing objects of this type in a deduced context, the signature of the - receiving function should use `static_streambuf` instead. + receiving function should use `static_buffer` instead. */ template -class static_streambuf_n - : public static_streambuf +class static_buffer_n + : public static_buffer #if ! BEAST_DOXYGEN , private boost::base_from_member< std::array> @@ -161,23 +161,23 @@ public: #if BEAST_DOXYGEN private: #endif - static_streambuf_n( - static_streambuf_n const&) = delete; - static_streambuf_n& operator=( - static_streambuf_n const&) = delete; + static_buffer_n( + static_buffer_n const&) = delete; + static_buffer_n& operator=( + static_buffer_n const&) = delete; #if BEAST_DOXYGEN public: #endif - /// Construct a static stream buffer. - static_streambuf_n() - : static_streambuf( + /// Construct a static buffer. + static_buffer_n() + : static_buffer( member_type::member.data(), member_type::member.size()) { } - /** Reset the stream buffer. + /** Reset the static buffer. Postconditions: The input sequence and output sequence are empty, @@ -186,7 +186,7 @@ public: void reset() { - static_streambuf::reset( + static_buffer::reset( member_type::member.data(), member_type::member.size()); } @@ -194,6 +194,6 @@ public: } // beast -#include +#include #endif diff --git a/include/beast/websocket/detail/frame.hpp b/include/beast/websocket/detail/frame.hpp index 2a0cb628..a41abe58 100644 --- a/include/beast/websocket/detail/frame.hpp +++ b/include/beast/websocket/detail/frame.hpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include @@ -38,11 +38,11 @@ struct frame_header // holds the largest possible frame header using fh_streambuf = - static_streambuf_n<14>; + static_buffer_n<14>; // holds the largest possible control frame using frame_streambuf = - static_streambuf_n< 2 + 8 + 4 + 125 >; + static_buffer_n< 2 + 8 + 4 + 125 >; inline bool constexpr diff --git a/include/beast/websocket/impl/close.ipp b/include/beast/websocket/impl/close.ipp index 983126f9..f3610eee 100644 --- a/include/beast/websocket/impl/close.ipp +++ b/include/beast/websocket/impl/close.ipp @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include @@ -43,7 +43,7 @@ class stream::close_op , cr(cr_) { ws.template write_close< - static_streambuf>(fb, cr); + static_buffer>(fb, cr); } }; @@ -235,7 +235,7 @@ close(close_reason const& cr, error_code& ec) BOOST_ASSERT(! wr_close_); wr_close_ = true; detail::frame_streambuf fb; - write_close(fb, cr); + write_close(fb, cr); boost::asio::write(stream_, fb.data(), ec); failed_ = ec != 0; } diff --git a/include/beast/websocket/impl/ping.ipp b/include/beast/websocket/impl/ping.ipp index 59071376..8ff4e3ae 100644 --- a/include/beast/websocket/impl/ping.ipp +++ b/include/beast/websocket/impl/ping.ipp @@ -42,7 +42,7 @@ class stream::ping_op using boost::asio::buffer; using boost::asio::buffer_copy; ws.template write_ping< - static_streambuf>(fb, op_, payload); + static_buffer>(fb, op_, payload); } }; @@ -246,7 +246,7 @@ stream:: ping(ping_data const& payload, error_code& ec) { detail::frame_streambuf db; - write_ping( + write_ping( db, opcode::ping, payload); boost::asio::write(stream_, db.data(), ec); } @@ -268,7 +268,7 @@ stream:: pong(ping_data const& payload, error_code& ec) { detail::frame_streambuf db; - write_ping( + write_ping( db, opcode::pong, payload); boost::asio::write(stream_, db.data(), ec); } diff --git a/include/beast/websocket/impl/read.ipp b/include/beast/websocket/impl/read.ipp index f8fac8e5..a9c1242d 100644 --- a/include/beast/websocket/impl/read.ipp +++ b/include/beast/websocket/impl/read.ipp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include @@ -444,7 +444,7 @@ operator()(error_code ec, d.state = do_read_fh; break; } - d.ws.template write_ping( + d.ws.template write_ping( d.fb, opcode::pong, payload); if(d.ws.wr_block_) { @@ -486,7 +486,7 @@ operator()(error_code ec, cr.reason = ""; d.fb.reset(); d.ws.template write_close< - static_streambuf>(d.fb, cr); + static_buffer>(d.fb, cr); if(d.ws.wr_block_) { // suspend @@ -620,7 +620,7 @@ operator()(error_code ec, } d.fb.reset(); d.ws.template write_close< - static_streambuf>(d.fb, code); + static_buffer>(d.fb, code); if(d.ws.wr_block_) { // suspend @@ -793,7 +793,7 @@ read_frame(frame_info& fi, DynamicBuffer& dynabuf, error_code& ec) fb.reset(); if(ping_cb_) ping_cb_(false, payload); - write_ping( + write_ping( fb, opcode::pong, payload); boost::asio::write(stream_, fb.data(), ec); failed_ = ec != 0; @@ -822,7 +822,7 @@ read_frame(frame_info& fi, DynamicBuffer& dynabuf, error_code& ec) cr.reason = ""; fb.reset(); wr_close_ = true; - write_close(fb, cr); + write_close(fb, cr); boost::asio::write(stream_, fb.data(), ec); failed_ = ec != 0; if(failed_) @@ -951,7 +951,7 @@ do_close: { wr_close_ = true; detail::frame_streambuf fb; - write_close(fb, code); + write_close(fb, code); boost::asio::write(stream_, fb.data(), ec); failed_ = ec != 0; if(failed_) diff --git a/include/beast/websocket/impl/stream.ipp b/include/beast/websocket/impl/stream.ipp index 3fc0bf6f..ec44014f 100644 --- a/include/beast/websocket/impl/stream.ipp +++ b/include/beast/websocket/impl/stream.ipp @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/beast/websocket/impl/write.ipp b/include/beast/websocket/impl/write.ipp index 37339947..8d1b2918 100644 --- a/include/beast/websocket/impl/write.ipp +++ b/include/beast/websocket/impl/write.ipp @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include @@ -234,7 +234,7 @@ operator()(error_code ec, BOOST_ASSERT(d.ws.wr_block_ == &d); d.fh.fin = d.fin; d.fh.len = buffer_size(d.cb); - detail::write( + detail::write( d.fh_buf, d.fh); d.ws.wr_.cont = ! d.fin; // Send frame @@ -260,7 +260,7 @@ operator()(error_code ec, d.remain -= n; d.fh.len = n; d.fh.fin = d.fin ? d.remain == 0 : false; - detail::write( + detail::write( d.fh_buf, d.fh); d.ws.wr_.cont = ! d.fin; // Send frame @@ -308,7 +308,7 @@ operator()(error_code ec, d.fh.len = d.remain; d.fh.key = d.ws.maskgen_(); detail::prepare_key(d.key, d.fh.key); - detail::write( + detail::write( d.fh_buf, d.fh); auto const n = clamp(d.remain, d.ws.wr_.buf_size); @@ -366,7 +366,7 @@ operator()(error_code ec, d.ws.wr_.buf.get(), n); buffer_copy(b, d.cb); detail::mask_inplace(b, d.key); - detail::write( + detail::write( d.fh_buf, d.fh); d.ws.wr_.cont = ! d.fin; // Send frame @@ -442,7 +442,7 @@ operator()(error_code ec, d.fh.fin = ! more; d.fh.len = n; detail::fh_streambuf fh_buf; - detail::write(fh_buf, d.fh); + detail::write(fh_buf, d.fh); d.ws.wr_.cont = ! d.fin; // Send frame d.state = more ? @@ -647,7 +647,7 @@ write_frame(bool fin, fh.fin = ! more; fh.len = n; detail::fh_streambuf fh_buf; - detail::write(fh_buf, fh); + detail::write(fh_buf, fh); wr_.cont = ! fin; boost::asio::write(stream_, buffer_cat(fh_buf.data(), b), ec); @@ -675,7 +675,7 @@ write_frame(bool fin, fh.fin = fin; fh.len = remain; detail::fh_streambuf fh_buf; - detail::write(fh_buf, fh); + detail::write(fh_buf, fh); wr_.cont = ! fin; boost::asio::write(stream_, buffer_cat(fh_buf.data(), buffers), ec); @@ -696,7 +696,7 @@ write_frame(bool fin, fh.len = n; fh.fin = fin ? remain == 0 : false; detail::fh_streambuf fh_buf; - detail::write(fh_buf, fh); + detail::write(fh_buf, fh); wr_.cont = ! fin; boost::asio::write(stream_, buffer_cat(fh_buf.data(), @@ -721,7 +721,7 @@ write_frame(bool fin, detail::prepared_key key; detail::prepare_key(key, fh.key); detail::fh_streambuf fh_buf; - detail::write(fh_buf, fh); + detail::write(fh_buf, fh); consuming_buffers< ConstBufferSequence> cb{buffers}; { @@ -772,7 +772,7 @@ write_frame(bool fin, fh.fin = fin ? remain == 0 : false; wr_.cont = ! fh.fin; detail::fh_streambuf fh_buf; - detail::write(fh_buf, fh); + detail::write(fh_buf, fh); boost::asio::write(stream_, buffer_cat(fh_buf.data(), b), ec); failed_ = ec != 0; diff --git a/test/Jamfile b/test/Jamfile index 2ab69509..b8f3c0d7 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -34,7 +34,7 @@ unit-test core-tests : core/placeholders.cpp core/prepare_buffer.cpp core/prepare_buffers.cpp - core/static_streambuf.cpp + core/static_buffer.cpp core/static_string.cpp core/stream_concepts.cpp core/base64.cpp diff --git a/test/core/CMakeLists.txt b/test/core/CMakeLists.txt index 67e6c403..6286ad97 100644 --- a/test/core/CMakeLists.txt +++ b/test/core/CMakeLists.txt @@ -27,7 +27,7 @@ add_executable (core-tests placeholders.cpp prepare_buffer.cpp prepare_buffers.cpp - static_streambuf.cpp + static_buffer.cpp static_string.cpp stream_concepts.cpp base64.cpp diff --git a/test/core/static_streambuf.cpp b/test/core/static_buffer.cpp similarity index 95% rename from test/core/static_streambuf.cpp rename to test/core/static_buffer.cpp index 0add8c4d..a6c02ba7 100644 --- a/test/core/static_streambuf.cpp +++ b/test/core/static_buffer.cpp @@ -6,7 +6,7 @@ // // Test that header file is self-contained. -#include +#include #include #include @@ -14,7 +14,7 @@ namespace beast { -class static_streambuf_test : public beast::unit_test::suite +class static_buffer_test : public beast::unit_test::suite { public: template @@ -32,7 +32,8 @@ public: return s; } - void testStaticStreambuf() + void + testStaticBuffer() { using boost::asio::buffer; using boost::asio::buffer_cast; @@ -50,7 +51,7 @@ public: std::size_t v = sizeof(buf) - (t + u); { std::memset(buf, 0, sizeof(buf)); - static_streambuf_n ba; + static_buffer_n ba; { auto d = ba.prepare(z); BEAST_EXPECT(buffer_size(d) == z); @@ -141,7 +142,7 @@ public: void testIterators() { - static_streambuf_n<2> ba; + static_buffer_n<2> ba; { auto mb = ba.prepare(2); std::size_t n; @@ -196,11 +197,11 @@ public: void run() override { - testStaticStreambuf(); + testStaticBuffer(); testIterators(); } }; -BEAST_DEFINE_TESTSUITE(static_streambuf,core,beast); +BEAST_DEFINE_TESTSUITE(static_buffer,core,beast); } // beastp