Skip to content

Commit

Permalink
Simplify payload length and mask parsing.
Browse files Browse the repository at this point in the history
Re-use the byteorder functions instead of pointer derefs.

Closes scylladb#1708
  • Loading branch information
voutilad authored and xemul committed Jul 7, 2023
1 parent da23228 commit f77507c
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/websocket/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,14 @@ future<websocket_parser::consumption_result_t> websocket_parser::operator()(
data.trim_front(required_bytes - hlen);

_payload_length = _header->length;
size_t offset = 0;
char const *input = _buffer.data();
if (_header->length == 126) {
_payload_length = be16toh(*(uint16_t const *)(input + offset));
offset += sizeof(uint16_t);
_payload_length = consume_be<uint16_t>(input);
} else if (_header->length == 127) {
_payload_length = be64toh(*(uint64_t const *)(input + offset));
offset += sizeof(uint64_t);
_payload_length = consume_be<uint64_t>(input);
}
_masking_key = be32toh(*(uint32_t const *)(input + offset));

_masking_key = consume_be<uint32_t>(input);
_buffer = {};
}
_state = parsing_state::payload;
Expand Down

0 comments on commit f77507c

Please sign in to comment.