Skip to content

Commit

Permalink
Pack data members in websocket stream
Browse files Browse the repository at this point in the history
  • Loading branch information
vinniefalco committed Sep 29, 2016
1 parent 0b0e356 commit ca9528a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Better WebSocket decorator
* Update and tidy documentation
* Use xor_shift_engine for calculating mask keys
* Pack data members in websocket stream

--------------------------------------------------------------------------------

Expand Down
14 changes: 7 additions & 7 deletions include/beast/websocket/detail/frame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace websocket {
namespace detail {

/// Identifies the role of a WebSockets stream.
enum class role_type
enum class role_type : std::uint8_t
{
/// Stream is operating as a client.
client,
Expand All @@ -36,14 +36,14 @@ enum class role_type
// Contents of a WebSocket frame header
struct frame_header
{
opcode op;
bool fin;
bool mask;
bool rsv1;
bool rsv2;
bool rsv3;
std::uint64_t len;
std::uint32_t key;
opcode op;
bool fin : 1;
bool mask : 1;
bool rsv1 : 1;
bool rsv2 : 1;
bool rsv3 : 1;
};

// holds the largest possible frame header
Expand Down
38 changes: 20 additions & 18 deletions include/beast/websocket/detail/stream_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,33 +60,34 @@ struct stream_base

detail::maskgen maskgen_; // source of mask keys
decorator_type d_; // adorns http messages
bool keep_alive_ = false; // close on failed upgrade
pong_cb pong_cb_; // pong callback
detail::utf8_checker rd_utf8_check_;// for current text msg
invokable rd_op_; // invoked after write completes
invokable wr_op_; // invoked after read completes
op* wr_block_; // op currenly writing
ping_data* pong_data_; // where to put pong payload

std::uint64_t rd_size_; // size of the current message so far
std::uint64_t rd_need_ = 0; // bytes left in msg frame payload
std::size_t rd_msg_max_ =
16 * 1024 * 1024; // max message size
std::size_t
wr_frag_size_ = 16 * 1024; // size of auto-fragments
std::size_t mask_buf_size_ = 4096; // mask buffer size
opcode wr_opcode_ = opcode::text; // outgoing message type
pong_cb pong_cb_; // pong callback
role_type role_; // server or client
bool failed_; // the connection failed

detail::frame_header rd_fh_; // current frame header
detail::prepared_key_type rd_key_; // prepared masking key
detail::utf8_checker rd_utf8_check_;// for current text msg
std::uint64_t rd_size_; // size of the current message so far
std::uint64_t rd_need_ = 0; // bytes left in msg frame payload
opcode rd_opcode_; // opcode of current msg
bool rd_cont_; // expecting a continuation frame

bool wr_close_; // sent close frame
bool wr_cont_; // next write is continuation frame
op* wr_block_; // op currenly writing

ping_data* pong_data_; // where to put pong payload
invokable rd_op_; // invoked after write completes
invokable wr_op_; // invoked after read completes
detail::frame_header rd_fh_; // current frame header
close_reason cr_; // set from received close frame
opcode rd_opcode_; // opcode of current msg
opcode wr_opcode_ = opcode::text; // outgoing message type
role_type role_; // server or client

bool failed_ : 1; // the connection failed
bool rd_cont_ : 1; // expecting a continuation frame
bool wr_close_ : 1; // sent close frame
bool wr_cont_ : 1; // next write is continuation frame
bool keep_alive_ : 1; // close on failed upgrade

stream_base(stream_base&&) = default;
stream_base(stream_base const&) = delete;
Expand All @@ -95,6 +96,7 @@ struct stream_base

stream_base()
: d_(new decorator<default_decorator>{})
, keep_alive_(false)
{
}

Expand Down

0 comments on commit ca9528a

Please sign in to comment.