Chris@16: // Chris@16: // ssl/old/stream_service.hpp Chris@16: // ~~~~~~~~~~~~~~~~~~~~~~~~~~ Chris@16: // Chris@16: // Copyright (c) 2005 Voipster / Indrek dot Juhani at voipster dot com Chris@101: // Copyright (c) 2005-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: Chris@16: #ifndef BOOST_ASIO_SSL_OLD_STREAM_SERVICE_HPP Chris@16: #define BOOST_ASIO_SSL_OLD_STREAM_SERVICE_HPP Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: # pragma once Chris@16: #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace asio { Chris@16: namespace ssl { Chris@16: namespace old { Chris@16: Chris@16: /// Default service implementation for an SSL stream. Chris@16: class stream_service Chris@16: #if defined(GENERATING_DOCUMENTATION) Chris@16: : public boost::asio::io_service::service Chris@16: #else Chris@16: : public boost::asio::detail::service_base Chris@16: #endif Chris@16: { Chris@16: private: Chris@16: // The type of the platform-specific implementation. Chris@16: typedef old::detail::openssl_stream_service service_impl_type; Chris@16: Chris@16: public: Chris@16: #if defined(GENERATING_DOCUMENTATION) Chris@16: /// The unique service identifier. Chris@16: static boost::asio::io_service::id id; Chris@16: #endif Chris@16: Chris@16: /// The type of a stream implementation. Chris@16: #if defined(GENERATING_DOCUMENTATION) Chris@16: typedef implementation_defined impl_type; Chris@16: #else Chris@16: typedef service_impl_type::impl_type impl_type; Chris@16: #endif Chris@16: Chris@16: /// Construct a new stream service for the specified io_service. Chris@16: explicit stream_service(boost::asio::io_service& io_service) Chris@16: : boost::asio::detail::service_base(io_service), Chris@16: service_impl_(boost::asio::use_service(io_service)) Chris@16: { Chris@16: } Chris@16: Chris@16: /// Return a null stream implementation. Chris@16: impl_type null() const Chris@16: { Chris@16: return service_impl_.null(); Chris@16: } Chris@16: Chris@16: /// Create a new stream implementation. Chris@16: template Chris@16: void create(impl_type& impl, Stream& next_layer, Chris@16: basic_context& context) Chris@16: { Chris@16: service_impl_.create(impl, next_layer, context); Chris@16: } Chris@16: Chris@16: /// Destroy a stream implementation. Chris@16: template Chris@16: void destroy(impl_type& impl, Stream& next_layer) Chris@16: { Chris@16: service_impl_.destroy(impl, next_layer); Chris@16: } Chris@16: Chris@16: /// Perform SSL handshaking. Chris@16: template Chris@16: boost::system::error_code handshake(impl_type& impl, Stream& next_layer, Chris@16: stream_base::handshake_type type, boost::system::error_code& ec) Chris@16: { Chris@16: return service_impl_.handshake(impl, next_layer, type, ec); Chris@16: } Chris@16: Chris@16: /// Start an asynchronous SSL handshake. Chris@16: template Chris@16: void async_handshake(impl_type& impl, Stream& next_layer, Chris@16: stream_base::handshake_type type, HandshakeHandler handler) Chris@16: { Chris@16: service_impl_.async_handshake(impl, next_layer, type, handler); Chris@16: } Chris@16: Chris@16: /// Shut down SSL on the stream. Chris@16: template Chris@16: boost::system::error_code shutdown(impl_type& impl, Stream& next_layer, Chris@16: boost::system::error_code& ec) Chris@16: { Chris@16: return service_impl_.shutdown(impl, next_layer, ec); Chris@16: } Chris@16: Chris@16: /// Asynchronously shut down SSL on the stream. Chris@16: template Chris@16: void async_shutdown(impl_type& impl, Stream& next_layer, Chris@16: ShutdownHandler handler) Chris@16: { Chris@16: service_impl_.async_shutdown(impl, next_layer, handler); Chris@16: } Chris@16: Chris@16: /// Write some data to the stream. Chris@16: template Chris@16: std::size_t write_some(impl_type& impl, Stream& next_layer, Chris@16: const ConstBufferSequence& buffers, boost::system::error_code& ec) Chris@16: { Chris@16: return service_impl_.write_some(impl, next_layer, buffers, ec); Chris@16: } Chris@16: Chris@16: /// Start an asynchronous write. Chris@16: template Chris@16: void async_write_some(impl_type& impl, Stream& next_layer, Chris@16: const ConstBufferSequence& buffers, WriteHandler handler) Chris@16: { Chris@16: service_impl_.async_write_some(impl, next_layer, buffers, handler); Chris@16: } Chris@16: Chris@16: /// Read some data from the stream. Chris@16: template Chris@16: std::size_t read_some(impl_type& impl, Stream& next_layer, Chris@16: const MutableBufferSequence& buffers, boost::system::error_code& ec) Chris@16: { Chris@16: return service_impl_.read_some(impl, next_layer, buffers, ec); Chris@16: } Chris@16: Chris@16: /// Start an asynchronous read. Chris@16: template Chris@16: void async_read_some(impl_type& impl, Stream& next_layer, Chris@16: const MutableBufferSequence& buffers, ReadHandler handler) Chris@16: { Chris@16: service_impl_.async_read_some(impl, next_layer, buffers, handler); Chris@16: } Chris@16: Chris@16: /// Peek at the incoming data on the stream. Chris@16: template Chris@16: std::size_t peek(impl_type& impl, Stream& next_layer, Chris@16: const MutableBufferSequence& buffers, boost::system::error_code& ec) Chris@16: { Chris@16: return service_impl_.peek(impl, next_layer, buffers, ec); Chris@16: } Chris@16: Chris@16: /// Determine the amount of data that may be read without blocking. Chris@16: template Chris@16: std::size_t in_avail(impl_type& impl, Stream& next_layer, Chris@16: boost::system::error_code& ec) Chris@16: { Chris@16: return service_impl_.in_avail(impl, next_layer, ec); Chris@16: } Chris@16: Chris@16: private: Chris@16: // Destroy all user-defined handler objects owned by the service. Chris@16: void shutdown_service() Chris@16: { Chris@16: } Chris@16: Chris@16: // The service that provides the platform-specific implementation. Chris@16: service_impl_type& service_impl_; Chris@16: }; Chris@16: Chris@16: } // namespace old Chris@16: } // namespace ssl Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_ASIO_SSL_OLD_STREAM_SERVICE_HPP