Skip to content

Commit

Permalink
Removes non-standards compliant masking behavior. fixes #469, fixes #395
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Thorson committed Oct 30, 2015
1 parent 6a94162 commit 4e2fb75
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 36 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ HEAD
long response before their HTTP handler ends would result in a second set of
HTTP headers being injected into the output. Thank you Kevin Smith for
reporting and providing test case details. #443
- Compatibility: Removes non-standards compliant masking behavior. Fixes #469,
Fixes #395

0.6.0
- MINOR BREAKING TRANSPORT POLICY CHANGE: Custom transport policies will now be
Expand Down
41 changes: 5 additions & 36 deletions websocketpp/processors/hybi13.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,19 +574,6 @@ class hybi13 : public processor<config> {
* Performs validation, masking, compression, etc. will return an error if
* there was an error, otherwise msg will be ready to be written
*
* By default WebSocket++ performs block masking/unmasking in a manner that
* makes assumptions about the nature of the machine and STL library used.
* In particular the assumption is either a 32 or 64 bit word size and an
* STL with std::string::data returning a contiguous char array.
*
* This method improves masking performance by 3-8x depending on the ratio
* of small to large messages and the availability of a 64 bit processor.
*
* To disable this optimization (for use with alternative STL
* implementations or processors) define WEBSOCKETPP_STRICT_MASKING when
* compiling the library. This will force the library to perform masking in
* single byte chunks.
*
* TODO: tests
*
* @param in An unprepared message to prepare
Expand Down Expand Up @@ -791,19 +778,9 @@ class hybi13 : public processor<config> {
{
// unmask if masked
if (frame::get_masked(m_basic_header)) {
#ifdef WEBSOCKETPP_STRICT_MASKING
m_current_msg->prepared_key = frame::byte_mask_circ(
buf,
len,
m_current_msg->prepared_key
);
#else
m_current_msg->prepared_key = frame::word_mask_circ(
buf,
len,
m_current_msg->prepared_key
);
#endif
m_current_msg->prepared_key = frame::byte_mask_circ(
buf, len, m_current_msg->prepared_key);
// TODO: SIMD masking
}

std::string & out = m_current_msg->msg_ptr->get_raw_payload();
Expand Down Expand Up @@ -962,16 +939,8 @@ class hybi13 : public processor<config> {
void masked_copy (std::string const & i, std::string & o,
frame::masking_key_type key) const
{
#ifdef WEBSOCKETPP_STRICT_MASKING
frame::byte_mask(i.begin(),i.end(),o.begin(),key);
#else
websocketpp::frame::word_mask_exact(
reinterpret_cast<uint8_t *>(const_cast<char *>(i.data())),
reinterpret_cast<uint8_t *>(const_cast<char *>(o.data())),
i.size(),
key
);
#endif
frame::byte_mask(i.begin(),i.end(),o.begin(),key);
// TODO: SIMD masking
}

/// Generic prepare control frame with opcode and payload.
Expand Down

0 comments on commit 4e2fb75

Please sign in to comment.