mirror of
https://github.com/boostorg/beast.git
synced 2025-07-29 20:37:31 +02:00
opcode is private (API Change):
* The opcode enum is removed. Actions Required: * Remove all occurences of the `opcode` enum at call sites
This commit is contained in:
11
CHANGELOG.md
11
CHANGELOG.md
@ -10,6 +10,7 @@ API Changes:
|
||||
* `ping_callback` is a member of stream
|
||||
* Remove `opcode` from `read`, `async_read`
|
||||
* `read_frame` returns `bool` fin
|
||||
* `opcode` is private
|
||||
|
||||
Actions Required:
|
||||
|
||||
@ -19,16 +20,16 @@ Actions Required:
|
||||
* Change call sites which use message_type with `set_option`
|
||||
to call `stream::binary` or `stream::text` instead.
|
||||
|
||||
* Change call sites which use read_buffer_size with `set_option` to
|
||||
* Change call sites which use 1read_buffer_size1 with `set_option` to
|
||||
call `stream::read_buffer_size` instead.
|
||||
|
||||
* Change call sites which use read_message_max with `set_option` to
|
||||
* Change call sites which use 1read_message_max1 with `set_option` to
|
||||
call `stream::read_message_max` instead.
|
||||
|
||||
* Change call sites which use write_buffer_size with `set_option` to
|
||||
* Change call sites which use 1write_buffer_size1 with `set_option` to
|
||||
call `stream::write_buffer_size` instead.
|
||||
|
||||
* Change call sites which use ping_callback with `set_option` to
|
||||
* Change call sites which use 1ping_callback1 with `set_option` to
|
||||
call `stream::ping_callback` instead.
|
||||
|
||||
* Remove the `opcode` reference parameter from calls to synchronous
|
||||
@ -43,6 +44,8 @@ Actions Required:
|
||||
the signature `void(error_code, bool fin)`, use the `bool`
|
||||
to indicate if the frame is the last frame.
|
||||
|
||||
* Remove all occurences of the `opcode` enum at call sites
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
Version 51
|
||||
|
@ -129,7 +129,6 @@
|
||||
<simplelist type="vert" columns="1">
|
||||
<member><link linkend="beast.ref.websocket__close_code">close_code</link></member>
|
||||
<member><link linkend="beast.ref.websocket__error">error</link></member>
|
||||
<member><link linkend="beast.ref.websocket__opcode">opcode</link></member>
|
||||
</simplelist>
|
||||
</entry>
|
||||
</row>
|
||||
|
@ -23,6 +23,27 @@ namespace beast {
|
||||
namespace websocket {
|
||||
namespace detail {
|
||||
|
||||
/** WebSocket frame header opcodes. */
|
||||
enum class opcode : std::uint8_t
|
||||
{
|
||||
cont = 0,
|
||||
text = 1,
|
||||
binary = 2,
|
||||
rsv3 = 3,
|
||||
rsv4 = 4,
|
||||
rsv5 = 5,
|
||||
rsv6 = 6,
|
||||
rsv7 = 7,
|
||||
close = 8,
|
||||
ping = 9,
|
||||
pong = 10,
|
||||
crsvb = 11,
|
||||
crsvc = 12,
|
||||
crsvd = 13,
|
||||
crsve = 14,
|
||||
crsvf = 15
|
||||
};
|
||||
|
||||
// Contents of a WebSocket frame header
|
||||
struct frame_header
|
||||
{
|
||||
|
@ -57,7 +57,8 @@ protected:
|
||||
bool wr_autofrag_ = true; // auto fragment
|
||||
std::size_t wr_buf_size_ = 4096; // write buffer size
|
||||
std::size_t rd_buf_size_ = 4096; // read buffer size
|
||||
opcode wr_opcode_ = opcode::text; // outgoing message type
|
||||
detail::opcode wr_opcode_ =
|
||||
detail::opcode::text; // outgoing message type
|
||||
ping_callback_type ping_cb_; // ping callback
|
||||
role_type role_; // server or client
|
||||
bool failed_; // the connection failed
|
||||
@ -76,7 +77,7 @@ protected:
|
||||
struct rd_t
|
||||
{
|
||||
// opcode of current message being read
|
||||
opcode op;
|
||||
detail::opcode op;
|
||||
|
||||
// `true` if the next frame is a continuation.
|
||||
bool cont;
|
||||
@ -194,7 +195,8 @@ protected:
|
||||
|
||||
template<class DynamicBuffer>
|
||||
void
|
||||
write_ping(DynamicBuffer& db, opcode op, ping_data const& data);
|
||||
write_ping(DynamicBuffer& db,
|
||||
detail::opcode op, ping_data const& data);
|
||||
};
|
||||
|
||||
template<class>
|
||||
@ -285,15 +287,16 @@ read_fh1(detail::frame_header& fh,
|
||||
fh.mask = (b[1] & 0x80) != 0;
|
||||
if(fh.mask)
|
||||
need += 4;
|
||||
fh.op = static_cast<opcode>(b[0] & 0x0f);
|
||||
fh.op = static_cast<
|
||||
detail::opcode>(b[0] & 0x0f);
|
||||
fh.fin = (b[0] & 0x80) != 0;
|
||||
fh.rsv1 = (b[0] & 0x40) != 0;
|
||||
fh.rsv2 = (b[0] & 0x20) != 0;
|
||||
fh.rsv3 = (b[0] & 0x10) != 0;
|
||||
switch(fh.op)
|
||||
{
|
||||
case opcode::binary:
|
||||
case opcode::text:
|
||||
case detail::opcode::binary:
|
||||
case detail::opcode::text:
|
||||
if(rd_.cont)
|
||||
{
|
||||
// new data frame when continuation expected
|
||||
@ -309,7 +312,7 @@ read_fh1(detail::frame_header& fh,
|
||||
pmd_->rd_set = fh.rsv1;
|
||||
break;
|
||||
|
||||
case opcode::cont:
|
||||
case detail::opcode::cont:
|
||||
if(! rd_.cont)
|
||||
{
|
||||
// continuation without an active message
|
||||
@ -418,7 +421,7 @@ read_fh2(detail::frame_header& fh,
|
||||
}
|
||||
if(! is_control(fh.op))
|
||||
{
|
||||
if(fh.op != opcode::cont)
|
||||
if(fh.op != detail::opcode::cont)
|
||||
{
|
||||
rd_.size = 0;
|
||||
rd_.op = fh.op;
|
||||
@ -485,7 +488,7 @@ write_close(DynamicBuffer& db, close_reason const& cr)
|
||||
{
|
||||
using namespace boost::endian;
|
||||
frame_header fh;
|
||||
fh.op = opcode::close;
|
||||
fh.op = detail::opcode::close;
|
||||
fh.fin = true;
|
||||
fh.rsv1 = false;
|
||||
fh.rsv2 = false;
|
||||
@ -528,8 +531,8 @@ write_close(DynamicBuffer& db, close_reason const& cr)
|
||||
template<class DynamicBuffer>
|
||||
void
|
||||
stream_base::
|
||||
write_ping(
|
||||
DynamicBuffer& db, opcode op, ping_data const& data)
|
||||
write_ping(DynamicBuffer& db,
|
||||
detail::opcode op, ping_data const& data)
|
||||
{
|
||||
frame_header fh;
|
||||
fh.op = op;
|
||||
|
@ -38,7 +38,7 @@ class stream<NextLayer>::ping_op
|
||||
int state = 0;
|
||||
|
||||
data(Handler& handler, stream<NextLayer>& ws_,
|
||||
opcode op_, ping_data const& payload)
|
||||
detail::opcode op_, ping_data const& payload)
|
||||
: ws(ws_)
|
||||
{
|
||||
using boost::asio::asio_handler_is_continuation;
|
||||
@ -212,7 +212,8 @@ async_ping(ping_data const& payload, WriteHandler&& handler)
|
||||
void(error_code)> init{handler};
|
||||
ping_op<handler_type<
|
||||
WriteHandler, void(error_code)>>{
|
||||
init.completion_handler, *this, opcode::ping, payload};
|
||||
init.completion_handler, *this,
|
||||
detail::opcode::ping, payload};
|
||||
return init.result.get();
|
||||
}
|
||||
|
||||
@ -229,7 +230,8 @@ async_pong(ping_data const& payload, WriteHandler&& handler)
|
||||
void(error_code)> init{handler};
|
||||
ping_op<handler_type<
|
||||
WriteHandler, void(error_code)>>{
|
||||
init.completion_handler, *this, opcode::pong, payload};
|
||||
init.completion_handler, *this,
|
||||
detail::opcode::pong, payload};
|
||||
return init.result.get();
|
||||
}
|
||||
|
||||
@ -251,7 +253,7 @@ ping(ping_data const& payload, error_code& ec)
|
||||
{
|
||||
detail::frame_streambuf db;
|
||||
write_ping<static_buffer>(
|
||||
db, opcode::ping, payload);
|
||||
db, detail::opcode::ping, payload);
|
||||
boost::asio::write(stream_, db.data(), ec);
|
||||
}
|
||||
|
||||
@ -273,7 +275,7 @@ pong(ping_data const& payload, error_code& ec)
|
||||
{
|
||||
detail::frame_streambuf db;
|
||||
write_ping<static_buffer>(
|
||||
db, opcode::pong, payload);
|
||||
db, detail::opcode::pong, payload);
|
||||
boost::asio::write(stream_, db.data(), ec);
|
||||
}
|
||||
|
||||
|
@ -237,7 +237,7 @@ operator()(error_code ec,
|
||||
bytes_transferred, *d.dmb);
|
||||
if(d.fh.mask)
|
||||
detail::mask_inplace(pb, d.key);
|
||||
if(d.ws.rd_.op == opcode::text)
|
||||
if(d.ws.rd_.op == detail::opcode::text)
|
||||
{
|
||||
if(! d.ws.rd_.utf8.write(pb) ||
|
||||
(d.remain == 0 && d.fh.fin &&
|
||||
@ -309,7 +309,7 @@ operator()(error_code ec,
|
||||
if(d.ws.failed_)
|
||||
break;
|
||||
}
|
||||
if(d.ws.rd_.op == opcode::text)
|
||||
if(d.ws.rd_.op == detail::opcode::text)
|
||||
{
|
||||
consuming_buffers<typename
|
||||
DynamicBuffer::const_buffers_type
|
||||
@ -402,8 +402,8 @@ operator()(error_code ec,
|
||||
d.state = do_control;
|
||||
break;
|
||||
}
|
||||
if(d.fh.op == opcode::text ||
|
||||
d.fh.op == opcode::binary)
|
||||
if(d.fh.op == detail::opcode::text ||
|
||||
d.fh.op == detail::opcode::binary)
|
||||
d.ws.rd_begin();
|
||||
if(d.fh.len == 0 && ! d.fh.fin)
|
||||
{
|
||||
@ -432,7 +432,7 @@ operator()(error_code ec,
|
||||
//------------------------------------------------------------------
|
||||
|
||||
case do_control:
|
||||
if(d.fh.op == opcode::ping)
|
||||
if(d.fh.op == detail::opcode::ping)
|
||||
{
|
||||
ping_data payload;
|
||||
detail::read(payload, d.fb.data());
|
||||
@ -446,7 +446,7 @@ operator()(error_code ec,
|
||||
break;
|
||||
}
|
||||
d.ws.template write_ping<static_buffer>(
|
||||
d.fb, opcode::pong, payload);
|
||||
d.fb, detail::opcode::pong, payload);
|
||||
if(d.ws.wr_block_)
|
||||
{
|
||||
// suspend
|
||||
@ -458,7 +458,7 @@ operator()(error_code ec,
|
||||
d.state = do_pong;
|
||||
break;
|
||||
}
|
||||
else if(d.fh.op == opcode::pong)
|
||||
else if(d.fh.op == detail::opcode::pong)
|
||||
{
|
||||
code = close_code::none;
|
||||
ping_data payload;
|
||||
@ -469,7 +469,7 @@ operator()(error_code ec,
|
||||
d.state = do_read_fh;
|
||||
break;
|
||||
}
|
||||
BOOST_ASSERT(d.fh.op == opcode::close);
|
||||
BOOST_ASSERT(d.fh.op == detail::opcode::close);
|
||||
{
|
||||
detail::read(d.ws.cr_, d.fb.data(), code);
|
||||
if(code != close_code::none)
|
||||
@ -786,22 +786,22 @@ read_frame(DynamicBuffer& dynabuf, error_code& ec)
|
||||
fb.commit(static_cast<std::size_t>(fh.len));
|
||||
}
|
||||
// Process control frame
|
||||
if(fh.op == opcode::ping)
|
||||
if(fh.op == detail::opcode::ping)
|
||||
{
|
||||
ping_data payload;
|
||||
detail::read(payload, fb.data());
|
||||
fb.consume(fb.size());
|
||||
if(ping_cb_)
|
||||
ping_cb_(false, payload);
|
||||
write_ping<static_buffer>(
|
||||
fb, opcode::pong, payload);
|
||||
write_ping<static_buffer>(fb,
|
||||
detail::opcode::pong, payload);
|
||||
boost::asio::write(stream_, fb.data(), ec);
|
||||
failed_ = ec != 0;
|
||||
if(failed_)
|
||||
return false;
|
||||
continue;
|
||||
}
|
||||
else if(fh.op == opcode::pong)
|
||||
else if(fh.op == detail::opcode::pong)
|
||||
{
|
||||
ping_data payload;
|
||||
detail::read(payload, fb.data());
|
||||
@ -809,7 +809,7 @@ read_frame(DynamicBuffer& dynabuf, error_code& ec)
|
||||
ping_cb_(true, payload);
|
||||
continue;
|
||||
}
|
||||
BOOST_ASSERT(fh.op == opcode::close);
|
||||
BOOST_ASSERT(fh.op == detail::opcode::close);
|
||||
{
|
||||
detail::read(cr_, fb.data(), code);
|
||||
if(code != close_code::none)
|
||||
@ -831,7 +831,7 @@ read_frame(DynamicBuffer& dynabuf, error_code& ec)
|
||||
goto do_close;
|
||||
}
|
||||
}
|
||||
if(fh.op != opcode::cont)
|
||||
if(fh.op != detail::opcode::cont)
|
||||
rd_begin();
|
||||
if(fh.len == 0 && ! fh.fin)
|
||||
{
|
||||
@ -868,7 +868,7 @@ read_frame(DynamicBuffer& dynabuf, error_code& ec)
|
||||
bytes_transferred, b);
|
||||
if(fh.mask)
|
||||
detail::mask_inplace(pb, key);
|
||||
if(rd_.op == opcode::text)
|
||||
if(rd_.op == detail::opcode::text)
|
||||
{
|
||||
if(! rd_.utf8.write(pb) ||
|
||||
(remain == 0 && fh.fin &&
|
||||
@ -915,7 +915,7 @@ read_frame(DynamicBuffer& dynabuf, error_code& ec)
|
||||
if(failed_)
|
||||
return false;
|
||||
}
|
||||
if(rd_.op == opcode::text)
|
||||
if(rd_.op == detail::opcode::text)
|
||||
{
|
||||
consuming_buffers<typename
|
||||
DynamicBuffer::const_buffers_type
|
||||
|
@ -179,7 +179,7 @@ operator()(error_code ec,
|
||||
d.fh.rsv2 = false;
|
||||
d.fh.rsv3 = false;
|
||||
d.fh.op = d.ws.wr_.cont ?
|
||||
opcode::cont : d.ws.wr_opcode_;
|
||||
detail::opcode::cont : d.ws.wr_opcode_;
|
||||
d.fh.mask =
|
||||
d.ws.role_ == detail::role_type::client;
|
||||
|
||||
@ -281,7 +281,7 @@ operator()(error_code ec,
|
||||
d.cb.consume(
|
||||
bytes_transferred - d.fh_buf.size());
|
||||
d.fh_buf.consume(d.fh_buf.size());
|
||||
d.fh.op = opcode::cont;
|
||||
d.fh.op = detail::opcode::cont;
|
||||
if(d.ws.wr_block_ == &d)
|
||||
d.ws.wr_block_ = nullptr;
|
||||
// Allow outgoing control frames to
|
||||
@ -386,7 +386,7 @@ operator()(error_code ec,
|
||||
d.cb.consume(
|
||||
bytes_transferred - d.fh_buf.size());
|
||||
d.fh_buf.consume(d.fh_buf.size());
|
||||
d.fh.op = opcode::cont;
|
||||
d.fh.op = detail::opcode::cont;
|
||||
BOOST_ASSERT(d.ws.wr_block_ == &d);
|
||||
d.ws.wr_block_ = nullptr;
|
||||
// Allow outgoing control frames to
|
||||
@ -458,7 +458,7 @@ operator()(error_code ec,
|
||||
}
|
||||
|
||||
case do_deflate + 2:
|
||||
d.fh.op = opcode::cont;
|
||||
d.fh.op = detail::opcode::cont;
|
||||
d.fh.rsv1 = false;
|
||||
BOOST_ASSERT(d.ws.wr_block_ == &d);
|
||||
d.ws.wr_block_ = nullptr;
|
||||
@ -612,7 +612,8 @@ write_frame(bool fin,
|
||||
}
|
||||
fh.rsv2 = false;
|
||||
fh.rsv3 = false;
|
||||
fh.op = wr_.cont ? opcode::cont : wr_opcode_;
|
||||
fh.op = wr_.cont ?
|
||||
detail::opcode::cont : wr_opcode_;
|
||||
fh.mask = role_ == detail::role_type::client;
|
||||
auto remain = buffer_size(buffers);
|
||||
if(wr_.compress)
|
||||
@ -658,7 +659,7 @@ write_frame(bool fin,
|
||||
return;
|
||||
if(! more)
|
||||
break;
|
||||
fh.op = opcode::cont;
|
||||
fh.op = detail::opcode::cont;
|
||||
fh.rsv1 = false;
|
||||
}
|
||||
if(fh.fin && (
|
||||
@ -708,7 +709,7 @@ write_frame(bool fin,
|
||||
return;
|
||||
if(remain == 0)
|
||||
break;
|
||||
fh.op = opcode::cont;
|
||||
fh.op = detail::opcode::cont;
|
||||
cb.consume(n);
|
||||
}
|
||||
}
|
||||
@ -782,7 +783,7 @@ write_frame(bool fin,
|
||||
return;
|
||||
if(remain == 0)
|
||||
break;
|
||||
fh.op = opcode::cont;
|
||||
fh.op = detail::opcode::cont;
|
||||
cb.consume(n);
|
||||
}
|
||||
return;
|
||||
|
@ -54,27 +54,6 @@ template<class Fields>
|
||||
bool
|
||||
is_upgrade(beast::http::header<true, Fields> const& req);
|
||||
|
||||
/** WebSocket frame header opcodes. */
|
||||
enum class opcode : std::uint8_t
|
||||
{
|
||||
cont = 0,
|
||||
text = 1,
|
||||
binary = 2,
|
||||
rsv3 = 3,
|
||||
rsv4 = 4,
|
||||
rsv5 = 5,
|
||||
rsv6 = 6,
|
||||
rsv7 = 7,
|
||||
close = 8,
|
||||
ping = 9,
|
||||
pong = 10,
|
||||
crsvb = 11,
|
||||
crsvc = 12,
|
||||
crsvd = 13,
|
||||
crsve = 14,
|
||||
crsvf = 15
|
||||
};
|
||||
|
||||
/** Close status codes.
|
||||
|
||||
These codes accompany close frames.
|
||||
|
@ -274,14 +274,16 @@ public:
|
||||
void
|
||||
binary(bool v)
|
||||
{
|
||||
wr_opcode_ = v ? opcode::binary : opcode::text;
|
||||
wr_opcode_ = v ?
|
||||
detail::opcode::binary :
|
||||
detail::opcode::text;
|
||||
}
|
||||
|
||||
/// Returns `true` if the binary message option is set.
|
||||
bool
|
||||
binary() const
|
||||
{
|
||||
return wr_opcode_ == opcode::binary;
|
||||
return wr_opcode_ == detail::opcode::binary;
|
||||
}
|
||||
|
||||
/** Set the ping callback.
|
||||
@ -455,14 +457,16 @@ public:
|
||||
void
|
||||
text(bool v)
|
||||
{
|
||||
wr_opcode_ = v ? opcode::text : opcode::binary;
|
||||
wr_opcode_ = v ?
|
||||
detail::opcode::text :
|
||||
detail::opcode::binary;
|
||||
}
|
||||
|
||||
/// Returns `true` if the text message option is set.
|
||||
bool
|
||||
text() const
|
||||
{
|
||||
return wr_opcode_ == opcode::text;
|
||||
return wr_opcode_ == detail::opcode::text;
|
||||
}
|
||||
|
||||
/** Returns the close reason received from the peer.
|
||||
@ -487,7 +491,7 @@ public:
|
||||
bool
|
||||
got_binary()
|
||||
{
|
||||
return rd_.op == opcode::binary;
|
||||
return rd_.op == detail::opcode::binary;
|
||||
}
|
||||
|
||||
/** Returns `true` if the latest message data indicates text.
|
||||
|
@ -55,7 +55,7 @@ public:
|
||||
{
|
||||
test_fh()
|
||||
{
|
||||
op = opcode::text;
|
||||
op = detail::opcode::text;
|
||||
fin = false;
|
||||
mask = false;
|
||||
rsv1 = false;
|
||||
@ -151,7 +151,7 @@ public:
|
||||
|
||||
test_fh fh;
|
||||
|
||||
fh.op = opcode::close;
|
||||
fh.op = detail::opcode::close;
|
||||
fh.fin = true;
|
||||
fh.len = 126;
|
||||
check(fh);
|
||||
@ -169,11 +169,11 @@ public:
|
||||
check(fh);
|
||||
fh.rsv3 = false;
|
||||
|
||||
fh.op = opcode::rsv3;
|
||||
fh.op = detail::opcode::rsv3;
|
||||
check(fh);
|
||||
fh.op = opcode::text;
|
||||
fh.op = detail::opcode::text;
|
||||
|
||||
fh.op = opcode::ping;
|
||||
fh.op = detail::opcode::ping;
|
||||
fh.fin = false;
|
||||
check(fh);
|
||||
fh.fin = true;
|
||||
|
@ -155,7 +155,6 @@ private:
|
||||
beast::websocket::stream<
|
||||
boost::asio::ssl::stream<socket_type>> ws;
|
||||
boost::asio::io_service::strand strand;
|
||||
beast::websocket::opcode op;
|
||||
beast::multi_buffer db;
|
||||
std::size_t id;
|
||||
|
||||
|
@ -214,7 +214,6 @@ private:
|
||||
int state = 0;
|
||||
beast::websocket::stream<socket_type> ws;
|
||||
boost::asio::io_service::strand strand;
|
||||
beast::websocket::opcode op;
|
||||
beast::multi_buffer db;
|
||||
std::size_t id;
|
||||
|
||||
|
Reference in New Issue
Block a user