1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042 |
- #ifndef ASIO_SSL_STREAM_HPP
- #define ASIO_SSL_STREAM_HPP
- #if defined(_MSC_VER) && (_MSC_VER >= 1200)
- # pragma once
- #endif
- #include "asio/detail/config.hpp"
- #include "asio/async_result.hpp"
- #include "asio/buffer.hpp"
- #include "asio/detail/buffer_sequence_adapter.hpp"
- #include "asio/detail/handler_type_requirements.hpp"
- #include "asio/detail/non_const_lvalue.hpp"
- #include "asio/detail/noncopyable.hpp"
- #include "asio/detail/type_traits.hpp"
- #include "asio/ssl/context.hpp"
- #include "asio/ssl/detail/buffered_handshake_op.hpp"
- #include "asio/ssl/detail/handshake_op.hpp"
- #include "asio/ssl/detail/io.hpp"
- #include "asio/ssl/detail/read_op.hpp"
- #include "asio/ssl/detail/shutdown_op.hpp"
- #include "asio/ssl/detail/stream_core.hpp"
- #include "asio/ssl/detail/write_op.hpp"
- #include "asio/ssl/stream_base.hpp"
- #include "asio/detail/push_options.hpp"
- namespace asio {
- namespace ssl {
- template <typename Stream>
- class stream :
- public stream_base,
- private noncopyable
- {
- private:
- class initiate_async_handshake;
- class initiate_async_buffered_handshake;
- class initiate_async_shutdown;
- class initiate_async_write_some;
- class initiate_async_read_some;
- public:
-
- typedef SSL* native_handle_type;
-
- struct impl_struct
- {
- SSL* ssl;
- };
-
- typedef remove_reference_t<Stream> next_layer_type;
-
- typedef typename next_layer_type::lowest_layer_type lowest_layer_type;
-
- typedef typename lowest_layer_type::executor_type executor_type;
-
-
- template <typename Arg>
- stream(Arg&& arg, context& ctx)
- : next_layer_(static_cast<Arg&&>(arg)),
- core_(ctx.native_handle(), next_layer_.lowest_layer().get_executor())
- {
- }
-
-
- template <typename Arg>
- stream(Arg&& arg, native_handle_type handle)
- : next_layer_(static_cast<Arg&&>(arg)),
- core_(handle, next_layer_.lowest_layer().get_executor())
- {
- }
-
-
- stream(stream&& other)
- : next_layer_(static_cast<Stream&&>(other.next_layer_)),
- core_(static_cast<detail::stream_core&&>(other.core_))
- {
- }
-
-
- stream& operator=(stream&& other)
- {
- if (this != &other)
- {
- next_layer_ = static_cast<Stream&&>(other.next_layer_);
- core_ = static_cast<detail::stream_core&&>(other.core_);
- }
- return *this;
- }
-
-
- ~stream()
- {
- }
-
-
- executor_type get_executor() noexcept
- {
- return next_layer_.lowest_layer().get_executor();
- }
-
-
- native_handle_type native_handle()
- {
- return core_.engine_.native_handle();
- }
-
-
- const next_layer_type& next_layer() const
- {
- return next_layer_;
- }
-
-
- next_layer_type& next_layer()
- {
- return next_layer_;
- }
-
-
- lowest_layer_type& lowest_layer()
- {
- return next_layer_.lowest_layer();
- }
-
-
- const lowest_layer_type& lowest_layer() const
- {
- return next_layer_.lowest_layer();
- }
-
-
- void set_verify_mode(verify_mode v)
- {
- asio::error_code ec;
- set_verify_mode(v, ec);
- asio::detail::throw_error(ec, "set_verify_mode");
- }
-
-
- ASIO_SYNC_OP_VOID set_verify_mode(
- verify_mode v, asio::error_code& ec)
- {
- core_.engine_.set_verify_mode(v, ec);
- ASIO_SYNC_OP_VOID_RETURN(ec);
- }
-
-
- void set_verify_depth(int depth)
- {
- asio::error_code ec;
- set_verify_depth(depth, ec);
- asio::detail::throw_error(ec, "set_verify_depth");
- }
-
-
- ASIO_SYNC_OP_VOID set_verify_depth(
- int depth, asio::error_code& ec)
- {
- core_.engine_.set_verify_depth(depth, ec);
- ASIO_SYNC_OP_VOID_RETURN(ec);
- }
-
-
- template <typename VerifyCallback>
- void set_verify_callback(VerifyCallback callback)
- {
- asio::error_code ec;
- this->set_verify_callback(callback, ec);
- asio::detail::throw_error(ec, "set_verify_callback");
- }
-
-
- template <typename VerifyCallback>
- ASIO_SYNC_OP_VOID set_verify_callback(VerifyCallback callback,
- asio::error_code& ec)
- {
- core_.engine_.set_verify_callback(
- new detail::verify_callback<VerifyCallback>(callback), ec);
- ASIO_SYNC_OP_VOID_RETURN(ec);
- }
-
-
- void handshake(handshake_type type)
- {
- asio::error_code ec;
- handshake(type, ec);
- asio::detail::throw_error(ec, "handshake");
- }
-
-
- ASIO_SYNC_OP_VOID handshake(handshake_type type,
- asio::error_code& ec)
- {
- detail::io(next_layer_, core_, detail::handshake_op(type), ec);
- ASIO_SYNC_OP_VOID_RETURN(ec);
- }
-
-
- template <typename ConstBufferSequence>
- void handshake(handshake_type type, const ConstBufferSequence& buffers)
- {
- asio::error_code ec;
- handshake(type, buffers, ec);
- asio::detail::throw_error(ec, "handshake");
- }
-
-
- template <typename ConstBufferSequence>
- ASIO_SYNC_OP_VOID handshake(handshake_type type,
- const ConstBufferSequence& buffers, asio::error_code& ec)
- {
- detail::io(next_layer_, core_,
- detail::buffered_handshake_op<ConstBufferSequence>(type, buffers), ec);
- ASIO_SYNC_OP_VOID_RETURN(ec);
- }
-
-
- template <
- ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code))
- HandshakeToken = default_completion_token_t<executor_type>>
- auto async_handshake(handshake_type type,
- HandshakeToken&& token = default_completion_token_t<executor_type>())
- -> decltype(
- async_initiate<HandshakeToken,
- void (asio::error_code)>(
- declval<initiate_async_handshake>(), token, type))
- {
- return async_initiate<HandshakeToken,
- void (asio::error_code)>(
- initiate_async_handshake(this), token, type);
- }
-
-
- template <typename ConstBufferSequence,
- ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
- std::size_t)) BufferedHandshakeToken
- = default_completion_token_t<executor_type>>
- auto async_handshake(handshake_type type, const ConstBufferSequence& buffers,
- BufferedHandshakeToken&& token
- = default_completion_token_t<executor_type>(),
- constraint_t<
- is_const_buffer_sequence<ConstBufferSequence>::value
- > = 0)
- -> decltype(
- async_initiate<BufferedHandshakeToken,
- void (asio::error_code, std::size_t)>(
- declval<initiate_async_buffered_handshake>(), token, type, buffers))
- {
- return async_initiate<BufferedHandshakeToken,
- void (asio::error_code, std::size_t)>(
- initiate_async_buffered_handshake(this), token, type, buffers);
- }
-
-
- void shutdown()
- {
- asio::error_code ec;
- shutdown(ec);
- asio::detail::throw_error(ec, "shutdown");
- }
-
-
- ASIO_SYNC_OP_VOID shutdown(asio::error_code& ec)
- {
- detail::io(next_layer_, core_, detail::shutdown_op(), ec);
- ASIO_SYNC_OP_VOID_RETURN(ec);
- }
-
-
- template <
- ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code))
- ShutdownToken
- = default_completion_token_t<executor_type>>
- auto async_shutdown(
- ShutdownToken&& token = default_completion_token_t<executor_type>())
- -> decltype(
- async_initiate<ShutdownToken,
- void (asio::error_code)>(
- declval<initiate_async_shutdown>(), token))
- {
- return async_initiate<ShutdownToken,
- void (asio::error_code)>(
- initiate_async_shutdown(this), token);
- }
-
-
- template <typename ConstBufferSequence>
- std::size_t write_some(const ConstBufferSequence& buffers)
- {
- asio::error_code ec;
- std::size_t n = write_some(buffers, ec);
- asio::detail::throw_error(ec, "write_some");
- return n;
- }
-
-
- template <typename ConstBufferSequence>
- std::size_t write_some(const ConstBufferSequence& buffers,
- asio::error_code& ec)
- {
- return detail::io(next_layer_, core_,
- detail::write_op<ConstBufferSequence>(buffers), ec);
- }
-
-
- template <typename ConstBufferSequence,
- ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
- std::size_t)) WriteToken = default_completion_token_t<executor_type>>
- auto async_write_some(const ConstBufferSequence& buffers,
- WriteToken&& token = default_completion_token_t<executor_type>())
- -> decltype(
- async_initiate<WriteToken,
- void (asio::error_code, std::size_t)>(
- declval<initiate_async_write_some>(), token, buffers))
- {
- return async_initiate<WriteToken,
- void (asio::error_code, std::size_t)>(
- initiate_async_write_some(this), token, buffers);
- }
-
-
- template <typename MutableBufferSequence>
- std::size_t read_some(const MutableBufferSequence& buffers)
- {
- asio::error_code ec;
- std::size_t n = read_some(buffers, ec);
- asio::detail::throw_error(ec, "read_some");
- return n;
- }
-
-
- template <typename MutableBufferSequence>
- std::size_t read_some(const MutableBufferSequence& buffers,
- asio::error_code& ec)
- {
- return detail::io(next_layer_, core_,
- detail::read_op<MutableBufferSequence>(buffers), ec);
- }
-
-
- template <typename MutableBufferSequence,
- ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
- std::size_t)) ReadToken = default_completion_token_t<executor_type>>
- auto async_read_some(const MutableBufferSequence& buffers,
- ReadToken&& token = default_completion_token_t<executor_type>())
- -> decltype(
- async_initiate<ReadToken,
- void (asio::error_code, std::size_t)>(
- declval<initiate_async_read_some>(), token, buffers))
- {
- return async_initiate<ReadToken,
- void (asio::error_code, std::size_t)>(
- initiate_async_read_some(this), token, buffers);
- }
- private:
- class initiate_async_handshake
- {
- public:
- typedef typename stream::executor_type executor_type;
- explicit initiate_async_handshake(stream* self)
- : self_(self)
- {
- }
- executor_type get_executor() const noexcept
- {
- return self_->get_executor();
- }
- template <typename HandshakeHandler>
- void operator()(HandshakeHandler&& handler,
- handshake_type type) const
- {
-
-
- ASIO_HANDSHAKE_HANDLER_CHECK(HandshakeHandler, handler) type_check;
- asio::detail::non_const_lvalue<HandshakeHandler> handler2(handler);
- detail::async_io(self_->next_layer_, self_->core_,
- detail::handshake_op(type), handler2.value);
- }
- private:
- stream* self_;
- };
- class initiate_async_buffered_handshake
- {
- public:
- typedef typename stream::executor_type executor_type;
- explicit initiate_async_buffered_handshake(stream* self)
- : self_(self)
- {
- }
- executor_type get_executor() const noexcept
- {
- return self_->get_executor();
- }
- template <typename BufferedHandshakeHandler, typename ConstBufferSequence>
- void operator()(BufferedHandshakeHandler&& handler,
- handshake_type type, const ConstBufferSequence& buffers) const
- {
-
-
-
- ASIO_BUFFERED_HANDSHAKE_HANDLER_CHECK(
- BufferedHandshakeHandler, handler) type_check;
- asio::detail::non_const_lvalue<
- BufferedHandshakeHandler> handler2(handler);
- detail::async_io(self_->next_layer_, self_->core_,
- detail::buffered_handshake_op<ConstBufferSequence>(type, buffers),
- handler2.value);
- }
- private:
- stream* self_;
- };
- class initiate_async_shutdown
- {
- public:
- typedef typename stream::executor_type executor_type;
- explicit initiate_async_shutdown(stream* self)
- : self_(self)
- {
- }
- executor_type get_executor() const noexcept
- {
- return self_->get_executor();
- }
- template <typename ShutdownHandler>
- void operator()(ShutdownHandler&& handler) const
- {
-
-
- ASIO_HANDSHAKE_HANDLER_CHECK(ShutdownHandler, handler) type_check;
- asio::detail::non_const_lvalue<ShutdownHandler> handler2(handler);
- detail::async_io(self_->next_layer_, self_->core_,
- detail::shutdown_op(), handler2.value);
- }
- private:
- stream* self_;
- };
- class initiate_async_write_some
- {
- public:
- typedef typename stream::executor_type executor_type;
- explicit initiate_async_write_some(stream* self)
- : self_(self)
- {
- }
- executor_type get_executor() const noexcept
- {
- return self_->get_executor();
- }
- template <typename WriteHandler, typename ConstBufferSequence>
- void operator()(WriteHandler&& handler,
- const ConstBufferSequence& buffers) const
- {
-
-
- ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
- asio::detail::non_const_lvalue<WriteHandler> handler2(handler);
- detail::async_io(self_->next_layer_, self_->core_,
- detail::write_op<ConstBufferSequence>(buffers), handler2.value);
- }
- private:
- stream* self_;
- };
- class initiate_async_read_some
- {
- public:
- typedef typename stream::executor_type executor_type;
- explicit initiate_async_read_some(stream* self)
- : self_(self)
- {
- }
- executor_type get_executor() const noexcept
- {
- return self_->get_executor();
- }
- template <typename ReadHandler, typename MutableBufferSequence>
- void operator()(ReadHandler&& handler,
- const MutableBufferSequence& buffers) const
- {
-
-
- ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
- asio::detail::non_const_lvalue<ReadHandler> handler2(handler);
- detail::async_io(self_->next_layer_, self_->core_,
- detail::read_op<MutableBufferSequence>(buffers), handler2.value);
- }
- private:
- stream* self_;
- };
- Stream next_layer_;
- detail::stream_core core_;
- };
- }
- }
- #include "asio/detail/pop_options.hpp"
- #endif
|