forked from boostorg/beast
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
permessage-deflate is a compile-time feature (API Change):
fix boostorg#849 This adds an additional `bool` template parameter to `websocket::stream`: * When deflateSupported is `true`, the stream will be capable of negotiating the permessage-deflate websocket extension per the configured run-time settings. * When deflateSupported is `false`, the stream will never negotiate the permessage-deflate websocket extension. Furthermore, all of the code necessary for implementing the permessage-deflate extension will be excluded from function instantiations. The resulting emitted object code should be smaller.
- Loading branch information
1 parent
65d92f6
commit 841ab84
Showing
20 changed files
with
1,236 additions
and
642 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
// | ||
// Copyright (c) 2016-2017 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 https://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
// Official repository: https://github.com/boostorg/beast | ||
// | ||
|
||
#ifndef BOOST_BEAST_WEBSOCKET_STREAM_BASE_HPP | ||
#define BOOST_BEAST_WEBSOCKET_STREAM_BASE_HPP | ||
|
||
#include <boost/beast/websocket/option.hpp> | ||
#include <boost/beast/websocket/detail/pmd_extension.hpp> | ||
#include <boost/beast/zlib/deflate_stream.hpp> | ||
#include <boost/beast/zlib/inflate_stream.hpp> | ||
#include <boost/beast/core/buffers_suffix.hpp> | ||
#include <boost/beast/core/error.hpp> | ||
#include <boost/asio/buffer.hpp> | ||
#include <cstdint> | ||
#include <memory> | ||
|
||
namespace boost { | ||
namespace beast { | ||
namespace websocket { | ||
namespace detail { | ||
|
||
template<bool deflateSupported> | ||
struct stream_base | ||
{ | ||
// State information for the permessage-deflate extension | ||
struct pmd_type | ||
{ | ||
// `true` if current read message is compressed | ||
bool rd_set = false; | ||
|
||
zlib::deflate_stream zo; | ||
zlib::inflate_stream zi; | ||
}; | ||
|
||
std::unique_ptr<pmd_type> pmd_; // pmd settings or nullptr | ||
permessage_deflate pmd_opts_; // local pmd options | ||
detail::pmd_offer pmd_config_; // offer (client) or negotiation (server) | ||
|
||
// return `true` if current message is deflated | ||
bool | ||
rd_deflated() const | ||
{ | ||
return pmd_ && pmd_->rd_set; | ||
} | ||
|
||
// set whether current message is deflated | ||
// returns `false` on protocol violation | ||
bool | ||
rd_deflated(bool rsv1) | ||
{ | ||
if(pmd_) | ||
{ | ||
pmd_->rd_set = rsv1; | ||
return true; | ||
} | ||
return ! rsv1; // pmd not negotiated | ||
} | ||
|
||
template<class ConstBufferSequence> | ||
bool | ||
deflate( | ||
boost::asio::mutable_buffer& out, | ||
buffers_suffix<ConstBufferSequence>& cb, | ||
bool fin, | ||
std::size_t& total_in, | ||
error_code& ec); | ||
|
||
void | ||
do_context_takeover_write(role_type role); | ||
|
||
void | ||
inflate( | ||
zlib::z_params& zs, | ||
zlib::Flush flush, | ||
error_code& ec); | ||
|
||
void | ||
do_context_takeover_read(role_type role); | ||
}; | ||
|
||
template<> | ||
struct stream_base<false> | ||
{ | ||
// These stubs are for avoiding linking in the zlib | ||
// code when permessage-deflate is not enabled. | ||
|
||
bool | ||
rd_deflated() const | ||
{ | ||
return false; | ||
} | ||
|
||
bool | ||
rd_deflated(bool rsv1) | ||
{ | ||
return ! rsv1; | ||
} | ||
|
||
template<class ConstBufferSequence> | ||
bool | ||
deflate( | ||
boost::asio::mutable_buffer&, | ||
buffers_suffix<ConstBufferSequence>&, | ||
bool, | ||
std::size_t&, | ||
error_code&) | ||
{ | ||
return false; | ||
} | ||
|
||
void | ||
do_context_takeover_write(role_type) | ||
{ | ||
} | ||
|
||
void | ||
inflate( | ||
zlib::z_params&, | ||
zlib::Flush, | ||
error_code&) | ||
{ | ||
} | ||
|
||
void | ||
do_context_takeover_read(role_type) | ||
{ | ||
} | ||
}; | ||
|
||
} // detail | ||
} // websocket | ||
} // beast | ||
} // boost | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.