123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717 |
- #ifndef BOOST_BEAST_CORE_SSL_STREAM_HPP
- #define BOOST_BEAST_CORE_SSL_STREAM_HPP
- #include <boost/beast/core/detail/config.hpp>
- #include <boost/beast/websocket/ssl.hpp>
- #include <boost/beast/core/flat_stream.hpp>
- #include <boost/asio/ssl/error.hpp>
- #include <boost/asio/ssl/stream.hpp>
- #include <cstddef>
- #include <memory>
- #include <type_traits>
- #include <utility>
- namespace boost {
- namespace beast {
- template<class NextLayer>
- class ssl_stream
- : public net::ssl::stream_base
- {
- using ssl_stream_type = net::ssl::stream<NextLayer>;
- using stream_type = boost::beast::flat_stream<ssl_stream_type>;
- std::unique_ptr<stream_type> p_;
- public:
-
- using native_handle_type =
- typename ssl_stream_type::native_handle_type;
-
- using impl_struct = typename ssl_stream_type::impl_struct;
-
- using next_layer_type = typename ssl_stream_type::next_layer_type;
-
- using executor_type = typename stream_type::executor_type;
-
- template<class Executor1>
- struct rebind_executor
- {
-
- using other = ssl_stream<
- typename stream_type::template rebind_executor<Executor1>::other
- >;
- };
-
- template<class Arg>
- ssl_stream(
- Arg&& arg,
- net::ssl::context& ctx)
- : p_(new stream_type{
- std::forward<Arg>(arg), ctx})
- {
- }
-
- executor_type
- get_executor() noexcept
- {
- return p_->get_executor();
- }
-
- native_handle_type
- native_handle() noexcept
- {
- return p_->next_layer().native_handle();
- }
-
- next_layer_type const&
- next_layer() const noexcept
- {
- return p_->next_layer().next_layer();
- }
-
- next_layer_type&
- next_layer() noexcept
- {
- return p_->next_layer().next_layer();
- }
-
- void
- set_verify_mode(net::ssl::verify_mode v)
- {
- p_->next_layer().set_verify_mode(v);
- }
-
- void
- set_verify_mode(net::ssl::verify_mode v,
- boost::system::error_code& ec)
- {
- p_->next_layer().set_verify_mode(v, ec);
- }
-
- void
- set_verify_depth(int depth)
- {
- p_->next_layer().set_verify_depth(depth);
- }
-
- void
- set_verify_depth(
- int depth, boost::system::error_code& ec)
- {
- p_->next_layer().set_verify_depth(depth, ec);
- }
-
- template<class VerifyCallback>
- void
- set_verify_callback(VerifyCallback callback)
- {
- p_->next_layer().set_verify_callback(callback);
- }
-
- template<class VerifyCallback>
- void
- set_verify_callback(VerifyCallback callback,
- boost::system::error_code& ec)
- {
- p_->next_layer().set_verify_callback(callback, ec);
- }
-
- void
- handshake(handshake_type type)
- {
- p_->next_layer().handshake(type);
- }
-
- void
- handshake(handshake_type type,
- boost::system::error_code& ec)
- {
- p_->next_layer().handshake(type, ec);
- }
-
- template<class ConstBufferSequence>
- void
- handshake(
- handshake_type type, ConstBufferSequence const& buffers)
- {
- p_->next_layer().handshake(type, buffers);
- }
-
- template<class ConstBufferSequence>
- void
- handshake(handshake_type type,
- ConstBufferSequence const& buffers,
- boost::system::error_code& ec)
- {
- p_->next_layer().handshake(type, buffers, ec);
- }
-
- template<BOOST_BEAST_ASYNC_TPARAM1 HandshakeHandler = net::default_completion_token_t<executor_type>>
- BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(HandshakeHandler, void(boost::system::error_code))
- async_handshake(handshake_type type,
- BOOST_ASIO_MOVE_ARG(HandshakeHandler) handler = net::default_completion_token_t<executor_type>{})
- {
- return p_->next_layer().async_handshake(type,
- BOOST_ASIO_MOVE_CAST(HandshakeHandler)(handler));
- }
-
- template<class ConstBufferSequence,
- BOOST_BEAST_ASYNC_TPARAM2 BufferedHandshakeHandler = net::default_completion_token_t<executor_type>>
- BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(BufferedHandshakeHandler, void(boost::system::error_code, std::size_t))
- async_handshake(handshake_type type, ConstBufferSequence const& buffers,
- BOOST_ASIO_MOVE_ARG(BufferedHandshakeHandler) handler
- = net::default_completion_token_t<executor_type>{})
- {
- return p_->next_layer().async_handshake(type, buffers,
- BOOST_ASIO_MOVE_CAST(BufferedHandshakeHandler)(handler));
- }
-
- void
- shutdown()
- {
- p_->next_layer().shutdown();
- }
-
- void
- shutdown(boost::system::error_code& ec)
- {
- p_->next_layer().shutdown(ec);
- }
-
- template<BOOST_BEAST_ASYNC_TPARAM1 ShutdownHandler = net::default_completion_token_t<executor_type>>
- BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ShutdownHandler, void(boost::system::error_code))
- async_shutdown(BOOST_ASIO_MOVE_ARG(ShutdownHandler) handler = net::default_completion_token_t<executor_type>{})
- {
- return p_->next_layer().async_shutdown(
- BOOST_ASIO_MOVE_CAST(ShutdownHandler)(handler));
- }
-
- template<class ConstBufferSequence>
- std::size_t
- write_some(ConstBufferSequence const& buffers)
- {
- return p_->write_some(buffers);
- }
-
- template<class ConstBufferSequence>
- std::size_t
- write_some(ConstBufferSequence const& buffers,
- boost::system::error_code& ec)
- {
- return p_->write_some(buffers, ec);
- }
-
- template<class ConstBufferSequence,
- BOOST_BEAST_ASYNC_TPARAM2 WriteHandler = net::default_completion_token_t<executor_type>>
- BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler, void(boost::system::error_code, std::size_t))
- async_write_some(ConstBufferSequence const& buffers,
- BOOST_ASIO_MOVE_ARG(WriteHandler) handler= net::default_completion_token_t<executor_type>{})
- {
- return p_->async_write_some(buffers,
- BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
- }
-
- template<class MutableBufferSequence>
- std::size_t
- read_some(MutableBufferSequence const& buffers)
- {
- return p_->read_some(buffers);
- }
-
- template<class MutableBufferSequence>
- std::size_t
- read_some(MutableBufferSequence const& buffers,
- boost::system::error_code& ec)
- {
- return p_->read_some(buffers, ec);
- }
-
- template<class MutableBufferSequence,
- BOOST_BEAST_ASYNC_TPARAM2 ReadHandler = net::default_completion_token_t<executor_type>>
- BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ReadHandler, void(boost::system::error_code, std::size_t))
- async_read_some(MutableBufferSequence const& buffers,
- BOOST_ASIO_MOVE_ARG(ReadHandler) handler
- = net::default_completion_token_t<executor_type>{})
- {
- return p_->async_read_some(buffers,
- BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
- }
-
-
-
- #if ! BOOST_BEAST_DOXYGEN
- template<class SyncStream>
- friend
- void
- teardown(
- boost::beast::role_type role,
- ssl_stream<SyncStream>& stream,
- boost::system::error_code& ec);
- template<class AsyncStream, typename TeardownHandler>
- friend
- void
- async_teardown(
- boost::beast::role_type role,
- ssl_stream<AsyncStream>& stream,
- TeardownHandler&& handler);
- #endif
- };
- #if ! BOOST_BEAST_DOXYGEN
- template<class SyncStream>
- void
- teardown(
- boost::beast::role_type role,
- ssl_stream<SyncStream>& stream,
- boost::system::error_code& ec)
- {
-
- using boost::beast::websocket::teardown;
- teardown(role, *stream.p_, ec);
- }
- template<class AsyncStream,
- typename TeardownHandler = net::default_completion_token_t<beast::executor_type<AsyncStream>>>
- void
- async_teardown(
- boost::beast::role_type role,
- ssl_stream<AsyncStream>& stream,
- TeardownHandler&& handler = net::default_completion_token_t<beast::executor_type<AsyncStream>>{})
- {
-
- using boost::beast::websocket::async_teardown;
- async_teardown(role, *stream.p_,
- std::forward<TeardownHandler>(handler));
- }
- #endif
- }
- }
- #endif
|