diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d8f9325..4b51e425 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Version 260: * More split compilation in rfc7230.hpp * Qualify calls to `beast::iequals` in basic_parser.ipp +* More split compilation in websocket/detail/mask.hpp -------------------------------------------------------------------------------- diff --git a/include/boost/beast/src.hpp b/include/boost/beast/src.hpp index 6debe246..2376c3fc 100644 --- a/include/boost/beast/src.hpp +++ b/include/boost/beast/src.hpp @@ -52,6 +52,7 @@ the program, with the macro BOOST_BEAST_SEPARATE_COMPILATION defined. #include #include +#include #include #include #include diff --git a/include/boost/beast/websocket/detail/mask.hpp b/include/boost/beast/websocket/detail/mask.hpp index ade89fda..58797372 100644 --- a/include/boost/beast/websocket/detail/mask.hpp +++ b/include/boost/beast/websocket/detail/mask.hpp @@ -26,62 +26,27 @@ namespace detail { using prepared_key = std::array; -inline +BOOST_BEAST_DECL void -prepare_key(prepared_key& prepared, std::uint32_t key) -{ - prepared[0] = (key >> 0) & 0xff; - prepared[1] = (key >> 8) & 0xff; - prepared[2] = (key >> 16) & 0xff; - prepared[3] = (key >> 24) & 0xff; -} - -template -void -rol(std::array& v, std::size_t n) -{ - auto v0 = v; - for(std::size_t i = 0; i < v.size(); ++i ) - v[i] = v0[(i + n) % v.size()]; -} +prepare_key(prepared_key& prepared, std::uint32_t key); // Apply mask in place // -inline +BOOST_BEAST_DECL void -mask_inplace(net::mutable_buffer& b, prepared_key& key) -{ - auto n = b.size(); - auto mask = key; // avoid aliasing - auto p = static_cast(b.data()); - while(n >= 4) - { - for(int i = 0; i < 4; ++i) - p[i] ^= mask[i]; - p += 4; - n -= 4; - } - if(n > 0) - { - for(std::size_t i = 0; i < n; ++i) - p[i] ^= mask[i]; - rol(key, n); - } -} +mask_inplace(net::mutable_buffer const& b, prepared_key& key); // Apply mask in place // -template< - class MutableBufferSequence, - class KeyType> +template void mask_inplace( MutableBufferSequence const& buffers, - KeyType& key) + prepared_key& key) { for(net::mutable_buffer b : beast::buffers_range_ref(buffers)) - mask_inplace(b, key); + detail::mask_inplace(b, key); } } // detail @@ -89,4 +54,10 @@ mask_inplace( } // beast } // boost + +#if BOOST_BEAST_HEADER_ONLY +#include +#endif + + #endif diff --git a/include/boost/beast/websocket/detail/mask.ipp b/include/boost/beast/websocket/detail/mask.ipp new file mode 100644 index 00000000..6c36d56b --- /dev/null +++ b/include/boost/beast/websocket/detail/mask.ipp @@ -0,0 +1,66 @@ +// +// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// Official repository: https://github.com/boostorg/beast +// + +#ifndef BOOST_BEAST_WEBSOCKET_DETAIL_MASK_IPP +#define BOOST_BEAST_WEBSOCKET_DETAIL_MASK_IPP + +#include + +namespace boost { +namespace beast { +namespace websocket { +namespace detail { + +void +prepare_key(prepared_key& prepared, std::uint32_t key) +{ + prepared[0] = (key >> 0) & 0xff; + prepared[1] = (key >> 8) & 0xff; + prepared[2] = (key >> 16) & 0xff; + prepared[3] = (key >> 24) & 0xff; +} + +inline +void +rol(prepared_key& v, std::size_t n) +{ + auto v0 = v; + for(std::size_t i = 0; i < v.size(); ++i ) + v[i] = v0[(i + n) % v.size()]; +} + +// Apply mask in place +// +void +mask_inplace(net::mutable_buffer const& b, prepared_key& key) +{ + auto n = b.size(); + auto const mask = key; // avoid aliasing + auto p = static_cast(b.data()); + while(n >= 4) + { + for(int i = 0; i < 4; ++i) + p[i] ^= mask[i]; + p += 4; + n -= 4; + } + if(n > 0) + { + for(std::size_t i = 0; i < n; ++i) + p[i] ^= mask[i]; + rol(key, n); + } +} + +} // detail +} // websocket +} // beast +} // boost + +#endif