From 3938e5d9ed2747ff6188679a861e88645ecdb19b Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Fri, 26 Aug 2016 09:06:55 -0400 Subject: [PATCH] Rename to DynamicBuffer (fix #47) --- include/beast/core/buffers_adapter.hpp | 4 +- include/beast/core/static_streambuf.hpp | 2 +- include/beast/core/streambuf.hpp | 4 +- test/http/message_fuzz.hpp | 66 +++++----- test/websocket/stream.cpp | 120 +++++++++---------- test/websocket/websocket_async_echo_peer.hpp | 34 +++--- test/websocket/websocket_sync_echo_peer.hpp | 10 +- 7 files changed, 120 insertions(+), 120 deletions(-) diff --git a/include/beast/core/buffers_adapter.hpp b/include/beast/core/buffers_adapter.hpp index fa116a29..23adee16 100644 --- a/include/beast/core/buffers_adapter.hpp +++ b/include/beast/core/buffers_adapter.hpp @@ -14,10 +14,10 @@ namespace beast { -/** Adapts a @b `MutableBufferSequence` into a @b `Streambuf`. +/** Adapts a @b `MutableBufferSequence` into a @b `DynamicBuffer`. This class wraps a @b `MutableBufferSequence` to meet the requirements - of @b `Streambuf`. Upon construction the input and output sequences are + of @b `DynamicBuffer`. Upon construction the input and output sequences are empty. A copy of the mutable buffer sequence object is stored; however, ownership of the underlying memory is not transferred. The caller is responsible for making sure that referenced memory remains valid diff --git a/include/beast/core/static_streambuf.hpp b/include/beast/core/static_streambuf.hpp index 2166ba20..eb1f6c9c 100644 --- a/include/beast/core/static_streambuf.hpp +++ b/include/beast/core/static_streambuf.hpp @@ -129,7 +129,7 @@ protected: //------------------------------------------------------------------------------ -/** A `Streambuf` with a fixed size internal buffer. +/** A `DynamicBuffer` with a fixed size internal buffer. @tparam N The number of bytes in the internal buffer. diff --git a/include/beast/core/streambuf.hpp b/include/beast/core/streambuf.hpp index 468c8dfa..1726543f 100644 --- a/include/beast/core/streambuf.hpp +++ b/include/beast/core/streambuf.hpp @@ -12,14 +12,14 @@ namespace beast { -/** A @b `Streambuf` that uses multiple buffers internally. +/** A @b `DynamicBuffer` that uses multiple buffers internally. The implementation uses a sequence of one or more character arrays of varying sizes. Additional character array objects are appended to the sequence to accommodate changes in the size of the character sequence. - @note Meets the requirements of @b `Streambuf`. + @note Meets the requirements of @b `DynamicBuffer`. */ using streambuf = basic_streambuf>; diff --git a/test/http/message_fuzz.hpp b/test/http/message_fuzz.hpp index 17420b86..e736c960 100644 --- a/test/http/message_fuzz.hpp +++ b/test/http/message_fuzz.hpp @@ -472,85 +472,85 @@ public: return s; } - template + template void - headers(Streambuf& sb) + headers(DynamicBuffer& db) { while(rand(6)) { - write(sb, field()); - write(sb, rand(4) ? ": " : ":"); - write(sb, value()); - write(sb, "\r\n"); + write(db, field()); + write(db, rand(4) ? ": " : ":"); + write(db, value()); + write(db, "\r\n"); } } - template + template void - body(Streambuf& sb) + body(DynamicBuffer& db) { if(! rand(4)) { - write(sb, "Content-Length: 0\r\n\r\n"); + write(db, "Content-Length: 0\r\n\r\n"); return; } if(rand(2)) { auto const len = rand(500); - write(sb, "Content-Length: ", len, "\r\n\r\n"); - for(auto const& b : sb.prepare(len)) + write(db, "Content-Length: ", len, "\r\n\r\n"); + for(auto const& b : db.prepare(len)) { auto p = boost::asio::buffer_cast(b); auto n = boost::asio::buffer_size(b); while(n--) *p++ = static_cast(32 + rand(26+26+10+6)); } - sb.commit(len); + db.commit(len); } else { auto len = rand(500); - write(sb, "Transfer-Encoding: chunked\r\n\r\n"); + write(db, "Transfer-Encoding: chunked\r\n\r\n"); while(len > 0) { auto n = std::min(1 + rand(300), len); len -= n; - write(sb, to_hex(n), "\r\n"); - for(auto const& b : sb.prepare(n)) + write(db, to_hex(n), "\r\n"); + for(auto const& b : db.prepare(n)) { auto p = boost::asio::buffer_cast(b); auto m = boost::asio::buffer_size(b); while(m--) *p++ = static_cast(32 + rand(26+26+10+6)); } - sb.commit(n); - write(sb, "\r\n"); + db.commit(n); + write(db, "\r\n"); } - write(sb, "0\r\n\r\n"); + write(db, "0\r\n\r\n"); } } - template + template void - request(Streambuf& sb) + request(DynamicBuffer& db) { - write(sb, method(), " ", uri(), " HTTP/1.1\r\n"); - headers(sb); - body(sb); + write(db, method(), " ", uri(), " HTTP/1.1\r\n"); + headers(db); + body(db); } - template + template void - response(Streambuf& sb) + response(DynamicBuffer& db) { - write(sb, "HTTP/1."); - write(sb, rand(2) ? "0" : "1"); - write(sb, " ", 100 + rand(401), " "); - write(sb, token()); - write(sb, "\r\n"); - headers(sb); - body(sb); - write(sb, "\r\n"); + write(db, "HTTP/1."); + write(db, rand(2) ? "0" : "1"); + write(db, " ", 100 + rand(401), " "); + write(db, token()); + write(db, "\r\n"); + headers(db); + body(db); + write(db, "\r\n"); } }; diff --git a/test/websocket/stream.cpp b/test/websocket/stream.cpp index de0b00fd..3b5a07a0 100644 --- a/test/websocket/stream.cpp +++ b/test/websocket/stream.cpp @@ -109,15 +109,15 @@ public: return false; } - template + template static void - read(stream& ws, opcode& op, Streambuf& sb) + read(stream& ws, opcode& op, DynamicBuffer& db) { frame_info fi; for(;;) { - ws.read_frame(fi, sb); + ws.read_frame(fi, db); op = fi.op; if(fi.fin) break; @@ -453,11 +453,11 @@ public: if(! expect(! ec, ec.message())) break; opcode op; - streambuf sb; - ws.read(op, sb, ec); + streambuf db; + ws.read(op, db, ec); if(! expect(! ec, ec.message())) break; - expect(to_string(sb.data()) == + expect(to_string(db.data()) == std::string{v.data(), v.size()}); v.push_back(n+1); } @@ -479,11 +479,11 @@ public: if(! expect(! ec, ec.message())) break; opcode op; - streambuf sb; - ws.async_read(op, sb, do_yield[ec]); + streambuf db; + ws.async_read(op, db, do_yield[ec]); if(! expect(! ec, ec.message())) break; - expect(to_string(sb.data()) == + expect(to_string(db.data()) == std::string{v.data(), v.size()}); v.push_back(n+1); } @@ -544,9 +544,9 @@ public: // Read opcode op; - streambuf sb; + streambuf db; ++count; - ws.async_read(op, sb, + ws.async_read(op, db, [&](error_code ec) { --count; @@ -600,11 +600,11 @@ public: ws.write(buffer_cat(sbuf("TEXT"), cbuf(0x03, 0xea, 0xf0, 0x28, 0x8c, 0xbc))); opcode op; - streambuf sb; + streambuf db; std::size_t count = 0; // Read text message with bad utf8. // Causes a close to be sent, blocking writes. - ws.async_read(op, sb, + ws.async_read(op, db, [&](error_code ec) { // Read should fail with protocol error @@ -612,7 +612,7 @@ public: expect(ec == error::failed, ec.message()); // Reads after failure are aborted - ws.async_read(op, sb, + ws.async_read(op, db, [&](error_code ec) { ++count; @@ -668,11 +668,11 @@ public: ws.set_option(message_type(opcode::binary)); ws.write(sbuf("CLOSE")); opcode op; - streambuf sb; + streambuf db; std::size_t count = 0; // Read a close frame. // Sends a close frame, blocking writes. - ws.async_read(op, sb, + ws.async_read(op, db, [&](error_code ec) { // Read should complete with error::closed @@ -734,9 +734,9 @@ public: ws.set_option(message_type(opcode::binary)); ws.write(sbuf("CLOSE")); opcode op; - streambuf sb; + streambuf db; std::size_t count = 0; - ws.async_read(op, sb, + ws.async_read(op, db, [&](error_code ec) { ++count; @@ -785,8 +785,8 @@ public: }); }); opcode op; - streambuf sb; - ws.async_read(op, sb, + streambuf db; + ws.async_read(op, db, [&](error_code ec) { expect(ec == error::closed, ec.message()); @@ -811,8 +811,8 @@ public: try { opcode op; - streambuf sb; - ws.read(op, sb); + streambuf db; + ws.read(op, db); fail(); return false; } @@ -846,10 +846,10 @@ public: { // receive echoed message opcode op; - streambuf sb; - read(ws, op, sb); + streambuf db; + read(ws, op, db); expect(op == opcode::text); - expect(to_string(sb.data()) == "Hello"); + expect(to_string(db.data()) == "Hello"); } // close, no payload @@ -882,11 +882,11 @@ public: { // receive echoed message opcode op; - streambuf sb; - ws.read(op, sb); + streambuf db; + ws.read(op, db); expect(pong == 1); expect(op == opcode::binary); - expect(to_string(sb.data()) == "Hello"); + expect(to_string(db.data()) == "Hello"); } ws.set_option(pong_callback{}); @@ -903,10 +903,10 @@ public: { // receive echoed message opcode op; - streambuf sb; - ws.read(op, sb); + streambuf db; + ws.read(op, db); expect(pong == 1); - expect(to_string(sb.data()) == "Hello, World!"); + expect(to_string(db.data()) == "Hello, World!"); } ws.set_option(pong_callback{}); @@ -916,9 +916,9 @@ public: { // receive echoed message opcode op; - streambuf sb; - ws.read(op, sb); - expect(to_string(sb.data()) == "Hello"); + streambuf db; + ws.read(op, db); + expect(to_string(db.data()) == "Hello"); } ws.set_option(auto_fragment_size(0)); @@ -930,9 +930,9 @@ public: { // receive echoed message opcode op; - streambuf sb; - ws.read(op, sb); - expect(to_string(sb.data()) == s); + streambuf db; + ws.read(op, db); + expect(to_string(db.data()) == s); } } @@ -944,10 +944,10 @@ public: { // receive echoed message opcode op; - streambuf sb; - ws.read(op, sb); + streambuf db; + ws.read(op, db); expect(op == opcode::text); - expect(to_string(sb.data()) == "Hello"); + expect(to_string(db.data()) == "Hello"); } // cause close @@ -1040,9 +1040,9 @@ public: [&](error_code ev) { opcode op; - streambuf sb; + streambuf db; error_code ec; - ws.async_read(op, sb, do_yield[ec]); + ws.async_read(op, db, do_yield[ec]); if(! ec) { fail(); @@ -1085,12 +1085,12 @@ public: { // receive echoed message opcode op; - streambuf sb; - ws.async_read(op, sb, do_yield[ec]); + streambuf db; + ws.async_read(op, db, do_yield[ec]); if(ec) throw system_error{ec}; expect(op == opcode::text); - expect(to_string(sb.data()) == "Hello"); + expect(to_string(db.data()) == "Hello"); } // close, no payload @@ -1133,12 +1133,12 @@ public: throw system_error{ec}; // receive echoed message opcode op; - streambuf sb; - ws.async_read(op, sb, do_yield[ec]); + streambuf db; + ws.async_read(op, db, do_yield[ec]); if(ec) throw system_error{ec}; expect(op == opcode::binary); - expect(to_string(sb.data()) == "Hello"); + expect(to_string(db.data()) == "Hello"); ws.set_option(pong_callback{}); } @@ -1161,11 +1161,11 @@ public: { // receive echoed message opcode op; - streambuf sb; - ws.async_read(op, sb, do_yield[ec]); + streambuf db; + ws.async_read(op, db, do_yield[ec]); if(ec) throw system_error{ec}; - expect(to_string(sb.data()) == "Hello, World!"); + expect(to_string(db.data()) == "Hello, World!"); } ws.set_option(pong_callback{}); } @@ -1176,11 +1176,11 @@ public: { // receive echoed message opcode op; - streambuf sb; - ws.async_read(op, sb, do_yield[ec]); + streambuf db; + ws.async_read(op, db, do_yield[ec]); if(ec) throw system_error{ec}; - expect(to_string(sb.data()) == "Hello"); + expect(to_string(db.data()) == "Hello"); } ws.set_option(auto_fragment_size(0)); @@ -1194,11 +1194,11 @@ public: { // receive echoed message opcode op; - streambuf sb; - ws.async_read(op, sb, do_yield[ec]); + streambuf db; + ws.async_read(op, db, do_yield[ec]); if(ec) throw system_error{ec}; - expect(to_string(sb.data()) == s); + expect(to_string(db.data()) == s); } } @@ -1214,12 +1214,12 @@ public: { // receive echoed message opcode op; - streambuf sb; - ws.async_read(op, sb, do_yield[ec]); + streambuf db; + ws.async_read(op, db, do_yield[ec]); if(ec) throw system_error{ec}; expect(op == opcode::text); - expect(to_string(sb.data()) == "Hello"); + expect(to_string(db.data()) == "Hello"); } // cause close diff --git a/test/websocket/websocket_async_echo_peer.hpp b/test/websocket/websocket_async_echo_peer.hpp index e374dc8c..35d468b3 100644 --- a/test/websocket/websocket_async_echo_peer.hpp +++ b/test/websocket/websocket_async_echo_peer.hpp @@ -94,7 +94,7 @@ private: stream ws; boost::asio::io_service::strand strand; opcode op; - beast::streambuf sb; + beast::streambuf db; int id; data(bool log_, socket_type&& sock_) @@ -177,22 +177,22 @@ private: } } - template + template static bool - match(Streambuf& sb, char const(&s)[N]) + match(DynamicBuffer& db, char const(&s)[N]) { using boost::asio::buffer; using boost::asio::buffer_copy; - if(sb.size() < N-1) + if(db.size() < N-1) return false; static_string t; t.resize(N-1); buffer_copy(buffer(t.data(), t.size()), - sb.data()); + db.data()); if(t != s) return false; - sb.consume(N-1); + db.consume(N-1); return true; } @@ -217,10 +217,10 @@ private: case 1: if(ec) return fail(ec, "async_handshake"); - d.sb.consume(d.sb.size()); + d.db.consume(d.db.size()); // read message d.state = 2; - d.ws.async_read(d.op, d.sb, + d.ws.async_read(d.op, d.db, d.strand.wrap(std::move(*this))); return; @@ -230,33 +230,33 @@ private: return; if(ec) return fail(ec, "async_read"); - if(match(d.sb, "RAW")) + if(match(d.db, "RAW")) { d.state = 1; boost::asio::async_write(d.ws.next_layer(), - d.sb.data(), d.strand.wrap(std::move(*this))); + d.db.data(), d.strand.wrap(std::move(*this))); return; } - else if(match(d.sb, "TEXT")) + else if(match(d.db, "TEXT")) { d.state = 1; d.ws.set_option(message_type{opcode::text}); d.ws.async_write( - d.sb.data(), d.strand.wrap(std::move(*this))); + d.db.data(), d.strand.wrap(std::move(*this))); return; } - else if(match(d.sb, "PING")) + else if(match(d.db, "PING")) { ping_data payload; - d.sb.consume(buffer_copy( + d.db.consume(buffer_copy( buffer(payload.data(), payload.size()), - d.sb.data())); + d.db.data())); d.state = 1; d.ws.async_ping(payload, d.strand.wrap(std::move(*this))); return; } - else if(match(d.sb, "CLOSE")) + else if(match(d.db, "CLOSE")) { d.state = 1; d.ws.async_close({}, @@ -266,7 +266,7 @@ private: // write message d.state = 1; d.ws.set_option(message_type(d.op)); - d.ws.async_write(d.sb.data(), + d.ws.async_write(d.db.data(), d.strand.wrap(std::move(*this))); return; diff --git a/test/websocket/websocket_sync_echo_peer.hpp b/test/websocket/websocket_sync_echo_peer.hpp index 6d066546..ba641ef5 100644 --- a/test/websocket/websocket_sync_echo_peer.hpp +++ b/test/websocket/websocket_sync_echo_peer.hpp @@ -151,22 +151,22 @@ private: } }; - template + template static bool - match(Streambuf& sb, char const(&s)[N]) + match(DynamicBuffer& db, char const(&s)[N]) { using boost::asio::buffer; using boost::asio::buffer_copy; - if(sb.size() < N-1) + if(db.size() < N-1) return false; static_string t; t.resize(N-1); buffer_copy(buffer(t.data(), t.size()), - sb.data()); + db.data()); if(t != s) return false; - sb.consume(N-1); + db.consume(N-1); return true; }