00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ASIO_SSL_STREAM_HPP
00013 #define ASIO_SSL_STREAM_HPP
00014
00015 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
00016 # pragma once
00017 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
00018
00019 #include "asio/detail/push_options.hpp"
00020
00021 #include "asio/detail/push_options.hpp"
00022 #include <cstddef>
00023 #include <boost/config.hpp>
00024 #include <boost/noncopyable.hpp>
00025 #include <boost/type_traits.hpp>
00026 #include "asio/detail/pop_options.hpp"
00027
00028 #include "asio/error.hpp"
00029 #include "asio/ssl/basic_context.hpp"
00030 #include "asio/ssl/stream_base.hpp"
00031 #include "asio/ssl/stream_service.hpp"
00032 #include "asio/detail/throw_error.hpp"
00033
00034 namespace asio {
00035 namespace ssl {
00036
00038
00057 template <typename Stream, typename Service = stream_service>
00058 class stream
00059 : public stream_base,
00060 private boost::noncopyable
00061 {
00062 public:
00064 typedef typename boost::remove_reference<Stream>::type next_layer_type;
00065
00067 typedef typename next_layer_type::lowest_layer_type lowest_layer_type;
00068
00070 typedef Service service_type;
00071
00073 typedef typename service_type::impl_type impl_type;
00074
00076
00084 template <typename Arg, typename Context_Service>
00085 explicit stream(Arg& arg, basic_context<Context_Service>& context)
00086 : next_layer_(arg),
00087 service_(asio::use_service<Service>(next_layer_.get_io_service())),
00088 impl_(service_.null())
00089 {
00090 service_.create(impl_, next_layer_, context);
00091 }
00092
00094 ~stream()
00095 {
00096 service_.destroy(impl_, next_layer_);
00097 }
00098
00101
00108 asio::io_service& io_service()
00109 {
00110 return next_layer_.get_io_service();
00111 }
00112
00114
00121 asio::io_service& get_io_service()
00122 {
00123 return next_layer_.get_io_service();
00124 }
00125
00127
00134 next_layer_type& next_layer()
00135 {
00136 return next_layer_;
00137 }
00138
00140
00147 lowest_layer_type& lowest_layer()
00148 {
00149 return next_layer_.lowest_layer();
00150 }
00151
00153
00158 impl_type impl()
00159 {
00160 return impl_;
00161 }
00162
00164
00173 void handshake(handshake_type type)
00174 {
00175 asio::error_code ec;
00176 service_.handshake(impl_, next_layer_, type, ec);
00177 asio::detail::throw_error(ec);
00178 }
00179
00181
00190 asio::error_code handshake(handshake_type type,
00191 asio::error_code& ec)
00192 {
00193 return service_.handshake(impl_, next_layer_, type, ec);
00194 }
00195
00197
00211 template <typename HandshakeHandler>
00212 void async_handshake(handshake_type type, HandshakeHandler handler)
00213 {
00214 service_.async_handshake(impl_, next_layer_, type, handler);
00215 }
00216
00218
00224 void shutdown()
00225 {
00226 asio::error_code ec;
00227 service_.shutdown(impl_, next_layer_, ec);
00228 asio::detail::throw_error(ec);
00229 }
00230
00232
00238 asio::error_code shutdown(asio::error_code& ec)
00239 {
00240 return service_.shutdown(impl_, next_layer_, ec);
00241 }
00242
00244
00255 template <typename ShutdownHandler>
00256 void async_shutdown(ShutdownHandler handler)
00257 {
00258 service_.async_shutdown(impl_, next_layer_, handler);
00259 }
00260
00262
00277 template <typename ConstBufferSequence>
00278 std::size_t write_some(const ConstBufferSequence& buffers)
00279 {
00280 asio::error_code ec;
00281 std::size_t s = service_.write_some(impl_, next_layer_, buffers, ec);
00282 asio::detail::throw_error(ec);
00283 return s;
00284 }
00285
00287
00302 template <typename ConstBufferSequence>
00303 std::size_t write_some(const ConstBufferSequence& buffers,
00304 asio::error_code& ec)
00305 {
00306 return service_.write_some(impl_, next_layer_, buffers, ec);
00307 }
00308
00310
00331 template <typename ConstBufferSequence, typename WriteHandler>
00332 void async_write_some(const ConstBufferSequence& buffers,
00333 WriteHandler handler)
00334 {
00335 service_.async_write_some(impl_, next_layer_, buffers, handler);
00336 }
00337
00339
00354 template <typename MutableBufferSequence>
00355 std::size_t read_some(const MutableBufferSequence& buffers)
00356 {
00357 asio::error_code ec;
00358 std::size_t s = service_.read_some(impl_, next_layer_, buffers, ec);
00359 asio::detail::throw_error(ec);
00360 return s;
00361 }
00362
00364
00379 template <typename MutableBufferSequence>
00380 std::size_t read_some(const MutableBufferSequence& buffers,
00381 asio::error_code& ec)
00382 {
00383 return service_.read_some(impl_, next_layer_, buffers, ec);
00384 }
00385
00387
00409 template <typename MutableBufferSequence, typename ReadHandler>
00410 void async_read_some(const MutableBufferSequence& buffers,
00411 ReadHandler handler)
00412 {
00413 service_.async_read_some(impl_, next_layer_, buffers, handler);
00414 }
00415
00417
00428 template <typename MutableBufferSequence>
00429 std::size_t peek(const MutableBufferSequence& buffers)
00430 {
00431 asio::error_code ec;
00432 std::size_t s = service_.peek(impl_, next_layer_, buffers, ec);
00433 asio::detail::throw_error(ec);
00434 return s;
00435 }
00436
00438
00449 template <typename MutableBufferSequence>
00450 std::size_t peek(const MutableBufferSequence& buffers,
00451 asio::error_code& ec)
00452 {
00453 return service_.peek(impl_, next_layer_, buffers, ec);
00454 }
00455
00457
00465 std::size_t in_avail()
00466 {
00467 asio::error_code ec;
00468 std::size_t s = service_.in_avail(impl_, next_layer_, ec);
00469 asio::detail::throw_error(ec);
00470 return s;
00471 }
00472
00474
00482 std::size_t in_avail(asio::error_code& ec)
00483 {
00484 return service_.in_avail(impl_, next_layer_, ec);
00485 }
00486
00487 private:
00489 Stream next_layer_;
00490
00492 service_type& service_;
00493
00495 impl_type impl_;
00496 };
00497
00498 }
00499 }
00500
00501 #include "asio/detail/pop_options.hpp"
00502
00503 #endif // ASIO_SSL_STREAM_HPP