mirror of
https://github.com/boostorg/beast.git
synced 2025-08-04 07:14:32 +02:00
Rename to DynamicBuffer (fix #47)
This commit is contained in:
@@ -14,10 +14,10 @@
|
|||||||
|
|
||||||
namespace beast {
|
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
|
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,
|
empty. A copy of the mutable buffer sequence object is stored; however,
|
||||||
ownership of the underlying memory is not transferred. The caller is
|
ownership of the underlying memory is not transferred. The caller is
|
||||||
responsible for making sure that referenced memory remains valid
|
responsible for making sure that referenced memory remains valid
|
||||||
|
@@ -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.
|
@tparam N The number of bytes in the internal buffer.
|
||||||
|
|
||||||
|
@@ -12,14 +12,14 @@
|
|||||||
|
|
||||||
namespace beast {
|
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
|
The implementation uses a sequence of one or more character arrays
|
||||||
of varying sizes. Additional character array objects are appended to
|
of varying sizes. Additional character array objects are appended to
|
||||||
the sequence to accommodate changes in the size of the character
|
the sequence to accommodate changes in the size of the character
|
||||||
sequence.
|
sequence.
|
||||||
|
|
||||||
@note Meets the requirements of @b `Streambuf`.
|
@note Meets the requirements of @b `DynamicBuffer`.
|
||||||
*/
|
*/
|
||||||
using streambuf = basic_streambuf<std::allocator<char>>;
|
using streambuf = basic_streambuf<std::allocator<char>>;
|
||||||
|
|
||||||
|
@@ -472,85 +472,85 @@ public:
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Streambuf>
|
template<class DynamicBuffer>
|
||||||
void
|
void
|
||||||
headers(Streambuf& sb)
|
headers(DynamicBuffer& db)
|
||||||
{
|
{
|
||||||
while(rand(6))
|
while(rand(6))
|
||||||
{
|
{
|
||||||
write(sb, field());
|
write(db, field());
|
||||||
write(sb, rand(4) ? ": " : ":");
|
write(db, rand(4) ? ": " : ":");
|
||||||
write(sb, value());
|
write(db, value());
|
||||||
write(sb, "\r\n");
|
write(db, "\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Streambuf>
|
template<class DynamicBuffer>
|
||||||
void
|
void
|
||||||
body(Streambuf& sb)
|
body(DynamicBuffer& db)
|
||||||
{
|
{
|
||||||
if(! rand(4))
|
if(! rand(4))
|
||||||
{
|
{
|
||||||
write(sb, "Content-Length: 0\r\n\r\n");
|
write(db, "Content-Length: 0\r\n\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(rand(2))
|
if(rand(2))
|
||||||
{
|
{
|
||||||
auto const len = rand(500);
|
auto const len = rand(500);
|
||||||
write(sb, "Content-Length: ", len, "\r\n\r\n");
|
write(db, "Content-Length: ", len, "\r\n\r\n");
|
||||||
for(auto const& b : sb.prepare(len))
|
for(auto const& b : db.prepare(len))
|
||||||
{
|
{
|
||||||
auto p = boost::asio::buffer_cast<char*>(b);
|
auto p = boost::asio::buffer_cast<char*>(b);
|
||||||
auto n = boost::asio::buffer_size(b);
|
auto n = boost::asio::buffer_size(b);
|
||||||
while(n--)
|
while(n--)
|
||||||
*p++ = static_cast<char>(32 + rand(26+26+10+6));
|
*p++ = static_cast<char>(32 + rand(26+26+10+6));
|
||||||
}
|
}
|
||||||
sb.commit(len);
|
db.commit(len);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto len = rand(500);
|
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)
|
while(len > 0)
|
||||||
{
|
{
|
||||||
auto n = std::min(1 + rand(300), len);
|
auto n = std::min(1 + rand(300), len);
|
||||||
len -= n;
|
len -= n;
|
||||||
write(sb, to_hex(n), "\r\n");
|
write(db, to_hex(n), "\r\n");
|
||||||
for(auto const& b : sb.prepare(n))
|
for(auto const& b : db.prepare(n))
|
||||||
{
|
{
|
||||||
auto p = boost::asio::buffer_cast<char*>(b);
|
auto p = boost::asio::buffer_cast<char*>(b);
|
||||||
auto m = boost::asio::buffer_size(b);
|
auto m = boost::asio::buffer_size(b);
|
||||||
while(m--)
|
while(m--)
|
||||||
*p++ = static_cast<char>(32 + rand(26+26+10+6));
|
*p++ = static_cast<char>(32 + rand(26+26+10+6));
|
||||||
}
|
}
|
||||||
sb.commit(n);
|
db.commit(n);
|
||||||
write(sb, "\r\n");
|
write(db, "\r\n");
|
||||||
}
|
}
|
||||||
write(sb, "0\r\n\r\n");
|
write(db, "0\r\n\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Streambuf>
|
template<class DynamicBuffer>
|
||||||
void
|
void
|
||||||
request(Streambuf& sb)
|
request(DynamicBuffer& db)
|
||||||
{
|
{
|
||||||
write(sb, method(), " ", uri(), " HTTP/1.1\r\n");
|
write(db, method(), " ", uri(), " HTTP/1.1\r\n");
|
||||||
headers(sb);
|
headers(db);
|
||||||
body(sb);
|
body(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Streambuf>
|
template<class DynamicBuffer>
|
||||||
void
|
void
|
||||||
response(Streambuf& sb)
|
response(DynamicBuffer& db)
|
||||||
{
|
{
|
||||||
write(sb, "HTTP/1.");
|
write(db, "HTTP/1.");
|
||||||
write(sb, rand(2) ? "0" : "1");
|
write(db, rand(2) ? "0" : "1");
|
||||||
write(sb, " ", 100 + rand(401), " ");
|
write(db, " ", 100 + rand(401), " ");
|
||||||
write(sb, token());
|
write(db, token());
|
||||||
write(sb, "\r\n");
|
write(db, "\r\n");
|
||||||
headers(sb);
|
headers(db);
|
||||||
body(sb);
|
body(db);
|
||||||
write(sb, "\r\n");
|
write(db, "\r\n");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -109,15 +109,15 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class NextLayer, class Streambuf>
|
template<class NextLayer, class DynamicBuffer>
|
||||||
static
|
static
|
||||||
void
|
void
|
||||||
read(stream<NextLayer>& ws, opcode& op, Streambuf& sb)
|
read(stream<NextLayer>& ws, opcode& op, DynamicBuffer& db)
|
||||||
{
|
{
|
||||||
frame_info fi;
|
frame_info fi;
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
ws.read_frame(fi, sb);
|
ws.read_frame(fi, db);
|
||||||
op = fi.op;
|
op = fi.op;
|
||||||
if(fi.fin)
|
if(fi.fin)
|
||||||
break;
|
break;
|
||||||
@@ -453,11 +453,11 @@ public:
|
|||||||
if(! expect(! ec, ec.message()))
|
if(! expect(! ec, ec.message()))
|
||||||
break;
|
break;
|
||||||
opcode op;
|
opcode op;
|
||||||
streambuf sb;
|
streambuf db;
|
||||||
ws.read(op, sb, ec);
|
ws.read(op, db, ec);
|
||||||
if(! expect(! ec, ec.message()))
|
if(! expect(! ec, ec.message()))
|
||||||
break;
|
break;
|
||||||
expect(to_string(sb.data()) ==
|
expect(to_string(db.data()) ==
|
||||||
std::string{v.data(), v.size()});
|
std::string{v.data(), v.size()});
|
||||||
v.push_back(n+1);
|
v.push_back(n+1);
|
||||||
}
|
}
|
||||||
@@ -479,11 +479,11 @@ public:
|
|||||||
if(! expect(! ec, ec.message()))
|
if(! expect(! ec, ec.message()))
|
||||||
break;
|
break;
|
||||||
opcode op;
|
opcode op;
|
||||||
streambuf sb;
|
streambuf db;
|
||||||
ws.async_read(op, sb, do_yield[ec]);
|
ws.async_read(op, db, do_yield[ec]);
|
||||||
if(! expect(! ec, ec.message()))
|
if(! expect(! ec, ec.message()))
|
||||||
break;
|
break;
|
||||||
expect(to_string(sb.data()) ==
|
expect(to_string(db.data()) ==
|
||||||
std::string{v.data(), v.size()});
|
std::string{v.data(), v.size()});
|
||||||
v.push_back(n+1);
|
v.push_back(n+1);
|
||||||
}
|
}
|
||||||
@@ -544,9 +544,9 @@ public:
|
|||||||
|
|
||||||
// Read
|
// Read
|
||||||
opcode op;
|
opcode op;
|
||||||
streambuf sb;
|
streambuf db;
|
||||||
++count;
|
++count;
|
||||||
ws.async_read(op, sb,
|
ws.async_read(op, db,
|
||||||
[&](error_code ec)
|
[&](error_code ec)
|
||||||
{
|
{
|
||||||
--count;
|
--count;
|
||||||
@@ -600,11 +600,11 @@ public:
|
|||||||
ws.write(buffer_cat(sbuf("TEXT"),
|
ws.write(buffer_cat(sbuf("TEXT"),
|
||||||
cbuf(0x03, 0xea, 0xf0, 0x28, 0x8c, 0xbc)));
|
cbuf(0x03, 0xea, 0xf0, 0x28, 0x8c, 0xbc)));
|
||||||
opcode op;
|
opcode op;
|
||||||
streambuf sb;
|
streambuf db;
|
||||||
std::size_t count = 0;
|
std::size_t count = 0;
|
||||||
// Read text message with bad utf8.
|
// Read text message with bad utf8.
|
||||||
// Causes a close to be sent, blocking writes.
|
// Causes a close to be sent, blocking writes.
|
||||||
ws.async_read(op, sb,
|
ws.async_read(op, db,
|
||||||
[&](error_code ec)
|
[&](error_code ec)
|
||||||
{
|
{
|
||||||
// Read should fail with protocol error
|
// Read should fail with protocol error
|
||||||
@@ -612,7 +612,7 @@ public:
|
|||||||
expect(ec == error::failed,
|
expect(ec == error::failed,
|
||||||
ec.message());
|
ec.message());
|
||||||
// Reads after failure are aborted
|
// Reads after failure are aborted
|
||||||
ws.async_read(op, sb,
|
ws.async_read(op, db,
|
||||||
[&](error_code ec)
|
[&](error_code ec)
|
||||||
{
|
{
|
||||||
++count;
|
++count;
|
||||||
@@ -668,11 +668,11 @@ public:
|
|||||||
ws.set_option(message_type(opcode::binary));
|
ws.set_option(message_type(opcode::binary));
|
||||||
ws.write(sbuf("CLOSE"));
|
ws.write(sbuf("CLOSE"));
|
||||||
opcode op;
|
opcode op;
|
||||||
streambuf sb;
|
streambuf db;
|
||||||
std::size_t count = 0;
|
std::size_t count = 0;
|
||||||
// Read a close frame.
|
// Read a close frame.
|
||||||
// Sends a close frame, blocking writes.
|
// Sends a close frame, blocking writes.
|
||||||
ws.async_read(op, sb,
|
ws.async_read(op, db,
|
||||||
[&](error_code ec)
|
[&](error_code ec)
|
||||||
{
|
{
|
||||||
// Read should complete with error::closed
|
// Read should complete with error::closed
|
||||||
@@ -734,9 +734,9 @@ public:
|
|||||||
ws.set_option(message_type(opcode::binary));
|
ws.set_option(message_type(opcode::binary));
|
||||||
ws.write(sbuf("CLOSE"));
|
ws.write(sbuf("CLOSE"));
|
||||||
opcode op;
|
opcode op;
|
||||||
streambuf sb;
|
streambuf db;
|
||||||
std::size_t count = 0;
|
std::size_t count = 0;
|
||||||
ws.async_read(op, sb,
|
ws.async_read(op, db,
|
||||||
[&](error_code ec)
|
[&](error_code ec)
|
||||||
{
|
{
|
||||||
++count;
|
++count;
|
||||||
@@ -785,8 +785,8 @@ public:
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
opcode op;
|
opcode op;
|
||||||
streambuf sb;
|
streambuf db;
|
||||||
ws.async_read(op, sb,
|
ws.async_read(op, db,
|
||||||
[&](error_code ec)
|
[&](error_code ec)
|
||||||
{
|
{
|
||||||
expect(ec == error::closed, ec.message());
|
expect(ec == error::closed, ec.message());
|
||||||
@@ -811,8 +811,8 @@ public:
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
opcode op;
|
opcode op;
|
||||||
streambuf sb;
|
streambuf db;
|
||||||
ws.read(op, sb);
|
ws.read(op, db);
|
||||||
fail();
|
fail();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -846,10 +846,10 @@ public:
|
|||||||
{
|
{
|
||||||
// receive echoed message
|
// receive echoed message
|
||||||
opcode op;
|
opcode op;
|
||||||
streambuf sb;
|
streambuf db;
|
||||||
read(ws, op, sb);
|
read(ws, op, db);
|
||||||
expect(op == opcode::text);
|
expect(op == opcode::text);
|
||||||
expect(to_string(sb.data()) == "Hello");
|
expect(to_string(db.data()) == "Hello");
|
||||||
}
|
}
|
||||||
|
|
||||||
// close, no payload
|
// close, no payload
|
||||||
@@ -882,11 +882,11 @@ public:
|
|||||||
{
|
{
|
||||||
// receive echoed message
|
// receive echoed message
|
||||||
opcode op;
|
opcode op;
|
||||||
streambuf sb;
|
streambuf db;
|
||||||
ws.read(op, sb);
|
ws.read(op, db);
|
||||||
expect(pong == 1);
|
expect(pong == 1);
|
||||||
expect(op == opcode::binary);
|
expect(op == opcode::binary);
|
||||||
expect(to_string(sb.data()) == "Hello");
|
expect(to_string(db.data()) == "Hello");
|
||||||
}
|
}
|
||||||
ws.set_option(pong_callback{});
|
ws.set_option(pong_callback{});
|
||||||
|
|
||||||
@@ -903,10 +903,10 @@ public:
|
|||||||
{
|
{
|
||||||
// receive echoed message
|
// receive echoed message
|
||||||
opcode op;
|
opcode op;
|
||||||
streambuf sb;
|
streambuf db;
|
||||||
ws.read(op, sb);
|
ws.read(op, db);
|
||||||
expect(pong == 1);
|
expect(pong == 1);
|
||||||
expect(to_string(sb.data()) == "Hello, World!");
|
expect(to_string(db.data()) == "Hello, World!");
|
||||||
}
|
}
|
||||||
ws.set_option(pong_callback{});
|
ws.set_option(pong_callback{});
|
||||||
|
|
||||||
@@ -916,9 +916,9 @@ public:
|
|||||||
{
|
{
|
||||||
// receive echoed message
|
// receive echoed message
|
||||||
opcode op;
|
opcode op;
|
||||||
streambuf sb;
|
streambuf db;
|
||||||
ws.read(op, sb);
|
ws.read(op, db);
|
||||||
expect(to_string(sb.data()) == "Hello");
|
expect(to_string(db.data()) == "Hello");
|
||||||
}
|
}
|
||||||
ws.set_option(auto_fragment_size(0));
|
ws.set_option(auto_fragment_size(0));
|
||||||
|
|
||||||
@@ -930,9 +930,9 @@ public:
|
|||||||
{
|
{
|
||||||
// receive echoed message
|
// receive echoed message
|
||||||
opcode op;
|
opcode op;
|
||||||
streambuf sb;
|
streambuf db;
|
||||||
ws.read(op, sb);
|
ws.read(op, db);
|
||||||
expect(to_string(sb.data()) == s);
|
expect(to_string(db.data()) == s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -944,10 +944,10 @@ public:
|
|||||||
{
|
{
|
||||||
// receive echoed message
|
// receive echoed message
|
||||||
opcode op;
|
opcode op;
|
||||||
streambuf sb;
|
streambuf db;
|
||||||
ws.read(op, sb);
|
ws.read(op, db);
|
||||||
expect(op == opcode::text);
|
expect(op == opcode::text);
|
||||||
expect(to_string(sb.data()) == "Hello");
|
expect(to_string(db.data()) == "Hello");
|
||||||
}
|
}
|
||||||
|
|
||||||
// cause close
|
// cause close
|
||||||
@@ -1040,9 +1040,9 @@ public:
|
|||||||
[&](error_code ev)
|
[&](error_code ev)
|
||||||
{
|
{
|
||||||
opcode op;
|
opcode op;
|
||||||
streambuf sb;
|
streambuf db;
|
||||||
error_code ec;
|
error_code ec;
|
||||||
ws.async_read(op, sb, do_yield[ec]);
|
ws.async_read(op, db, do_yield[ec]);
|
||||||
if(! ec)
|
if(! ec)
|
||||||
{
|
{
|
||||||
fail();
|
fail();
|
||||||
@@ -1085,12 +1085,12 @@ public:
|
|||||||
{
|
{
|
||||||
// receive echoed message
|
// receive echoed message
|
||||||
opcode op;
|
opcode op;
|
||||||
streambuf sb;
|
streambuf db;
|
||||||
ws.async_read(op, sb, do_yield[ec]);
|
ws.async_read(op, db, do_yield[ec]);
|
||||||
if(ec)
|
if(ec)
|
||||||
throw system_error{ec};
|
throw system_error{ec};
|
||||||
expect(op == opcode::text);
|
expect(op == opcode::text);
|
||||||
expect(to_string(sb.data()) == "Hello");
|
expect(to_string(db.data()) == "Hello");
|
||||||
}
|
}
|
||||||
|
|
||||||
// close, no payload
|
// close, no payload
|
||||||
@@ -1133,12 +1133,12 @@ public:
|
|||||||
throw system_error{ec};
|
throw system_error{ec};
|
||||||
// receive echoed message
|
// receive echoed message
|
||||||
opcode op;
|
opcode op;
|
||||||
streambuf sb;
|
streambuf db;
|
||||||
ws.async_read(op, sb, do_yield[ec]);
|
ws.async_read(op, db, do_yield[ec]);
|
||||||
if(ec)
|
if(ec)
|
||||||
throw system_error{ec};
|
throw system_error{ec};
|
||||||
expect(op == opcode::binary);
|
expect(op == opcode::binary);
|
||||||
expect(to_string(sb.data()) == "Hello");
|
expect(to_string(db.data()) == "Hello");
|
||||||
ws.set_option(pong_callback{});
|
ws.set_option(pong_callback{});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1161,11 +1161,11 @@ public:
|
|||||||
{
|
{
|
||||||
// receive echoed message
|
// receive echoed message
|
||||||
opcode op;
|
opcode op;
|
||||||
streambuf sb;
|
streambuf db;
|
||||||
ws.async_read(op, sb, do_yield[ec]);
|
ws.async_read(op, db, do_yield[ec]);
|
||||||
if(ec)
|
if(ec)
|
||||||
throw system_error{ec};
|
throw system_error{ec};
|
||||||
expect(to_string(sb.data()) == "Hello, World!");
|
expect(to_string(db.data()) == "Hello, World!");
|
||||||
}
|
}
|
||||||
ws.set_option(pong_callback{});
|
ws.set_option(pong_callback{});
|
||||||
}
|
}
|
||||||
@@ -1176,11 +1176,11 @@ public:
|
|||||||
{
|
{
|
||||||
// receive echoed message
|
// receive echoed message
|
||||||
opcode op;
|
opcode op;
|
||||||
streambuf sb;
|
streambuf db;
|
||||||
ws.async_read(op, sb, do_yield[ec]);
|
ws.async_read(op, db, do_yield[ec]);
|
||||||
if(ec)
|
if(ec)
|
||||||
throw system_error{ec};
|
throw system_error{ec};
|
||||||
expect(to_string(sb.data()) == "Hello");
|
expect(to_string(db.data()) == "Hello");
|
||||||
}
|
}
|
||||||
ws.set_option(auto_fragment_size(0));
|
ws.set_option(auto_fragment_size(0));
|
||||||
|
|
||||||
@@ -1194,11 +1194,11 @@ public:
|
|||||||
{
|
{
|
||||||
// receive echoed message
|
// receive echoed message
|
||||||
opcode op;
|
opcode op;
|
||||||
streambuf sb;
|
streambuf db;
|
||||||
ws.async_read(op, sb, do_yield[ec]);
|
ws.async_read(op, db, do_yield[ec]);
|
||||||
if(ec)
|
if(ec)
|
||||||
throw system_error{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
|
// receive echoed message
|
||||||
opcode op;
|
opcode op;
|
||||||
streambuf sb;
|
streambuf db;
|
||||||
ws.async_read(op, sb, do_yield[ec]);
|
ws.async_read(op, db, do_yield[ec]);
|
||||||
if(ec)
|
if(ec)
|
||||||
throw system_error{ec};
|
throw system_error{ec};
|
||||||
expect(op == opcode::text);
|
expect(op == opcode::text);
|
||||||
expect(to_string(sb.data()) == "Hello");
|
expect(to_string(db.data()) == "Hello");
|
||||||
}
|
}
|
||||||
|
|
||||||
// cause close
|
// cause close
|
||||||
|
@@ -94,7 +94,7 @@ private:
|
|||||||
stream<socket_type> ws;
|
stream<socket_type> ws;
|
||||||
boost::asio::io_service::strand strand;
|
boost::asio::io_service::strand strand;
|
||||||
opcode op;
|
opcode op;
|
||||||
beast::streambuf sb;
|
beast::streambuf db;
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
data(bool log_, socket_type&& sock_)
|
data(bool log_, socket_type&& sock_)
|
||||||
@@ -177,22 +177,22 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Streambuf, std::size_t N>
|
template<class DynamicBuffer, std::size_t N>
|
||||||
static
|
static
|
||||||
bool
|
bool
|
||||||
match(Streambuf& sb, char const(&s)[N])
|
match(DynamicBuffer& db, char const(&s)[N])
|
||||||
{
|
{
|
||||||
using boost::asio::buffer;
|
using boost::asio::buffer;
|
||||||
using boost::asio::buffer_copy;
|
using boost::asio::buffer_copy;
|
||||||
if(sb.size() < N-1)
|
if(db.size() < N-1)
|
||||||
return false;
|
return false;
|
||||||
static_string<N-1> t;
|
static_string<N-1> t;
|
||||||
t.resize(N-1);
|
t.resize(N-1);
|
||||||
buffer_copy(buffer(t.data(), t.size()),
|
buffer_copy(buffer(t.data(), t.size()),
|
||||||
sb.data());
|
db.data());
|
||||||
if(t != s)
|
if(t != s)
|
||||||
return false;
|
return false;
|
||||||
sb.consume(N-1);
|
db.consume(N-1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,10 +217,10 @@ private:
|
|||||||
case 1:
|
case 1:
|
||||||
if(ec)
|
if(ec)
|
||||||
return fail(ec, "async_handshake");
|
return fail(ec, "async_handshake");
|
||||||
d.sb.consume(d.sb.size());
|
d.db.consume(d.db.size());
|
||||||
// read message
|
// read message
|
||||||
d.state = 2;
|
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)));
|
d.strand.wrap(std::move(*this)));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -230,33 +230,33 @@ private:
|
|||||||
return;
|
return;
|
||||||
if(ec)
|
if(ec)
|
||||||
return fail(ec, "async_read");
|
return fail(ec, "async_read");
|
||||||
if(match(d.sb, "RAW"))
|
if(match(d.db, "RAW"))
|
||||||
{
|
{
|
||||||
d.state = 1;
|
d.state = 1;
|
||||||
boost::asio::async_write(d.ws.next_layer(),
|
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;
|
return;
|
||||||
}
|
}
|
||||||
else if(match(d.sb, "TEXT"))
|
else if(match(d.db, "TEXT"))
|
||||||
{
|
{
|
||||||
d.state = 1;
|
d.state = 1;
|
||||||
d.ws.set_option(message_type{opcode::text});
|
d.ws.set_option(message_type{opcode::text});
|
||||||
d.ws.async_write(
|
d.ws.async_write(
|
||||||
d.sb.data(), d.strand.wrap(std::move(*this)));
|
d.db.data(), d.strand.wrap(std::move(*this)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if(match(d.sb, "PING"))
|
else if(match(d.db, "PING"))
|
||||||
{
|
{
|
||||||
ping_data payload;
|
ping_data payload;
|
||||||
d.sb.consume(buffer_copy(
|
d.db.consume(buffer_copy(
|
||||||
buffer(payload.data(), payload.size()),
|
buffer(payload.data(), payload.size()),
|
||||||
d.sb.data()));
|
d.db.data()));
|
||||||
d.state = 1;
|
d.state = 1;
|
||||||
d.ws.async_ping(payload,
|
d.ws.async_ping(payload,
|
||||||
d.strand.wrap(std::move(*this)));
|
d.strand.wrap(std::move(*this)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if(match(d.sb, "CLOSE"))
|
else if(match(d.db, "CLOSE"))
|
||||||
{
|
{
|
||||||
d.state = 1;
|
d.state = 1;
|
||||||
d.ws.async_close({},
|
d.ws.async_close({},
|
||||||
@@ -266,7 +266,7 @@ private:
|
|||||||
// write message
|
// write message
|
||||||
d.state = 1;
|
d.state = 1;
|
||||||
d.ws.set_option(message_type(d.op));
|
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)));
|
d.strand.wrap(std::move(*this)));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@@ -151,22 +151,22 @@ private:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class Streambuf, std::size_t N>
|
template<class DynamicBuffer, std::size_t N>
|
||||||
static
|
static
|
||||||
bool
|
bool
|
||||||
match(Streambuf& sb, char const(&s)[N])
|
match(DynamicBuffer& db, char const(&s)[N])
|
||||||
{
|
{
|
||||||
using boost::asio::buffer;
|
using boost::asio::buffer;
|
||||||
using boost::asio::buffer_copy;
|
using boost::asio::buffer_copy;
|
||||||
if(sb.size() < N-1)
|
if(db.size() < N-1)
|
||||||
return false;
|
return false;
|
||||||
static_string<N-1> t;
|
static_string<N-1> t;
|
||||||
t.resize(N-1);
|
t.resize(N-1);
|
||||||
buffer_copy(buffer(t.data(), t.size()),
|
buffer_copy(buffer(t.data(), t.size()),
|
||||||
sb.data());
|
db.data());
|
||||||
if(t != s)
|
if(t != s)
|
||||||
return false;
|
return false;
|
||||||
sb.consume(N-1);
|
db.consume(N-1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user