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
00058 template <typename Stream, typename Service = stream_service>
00059 class stream
00060 : public stream_base,
00061 private boost::noncopyable
00062 {
00063 public:
00065 typedef typename boost::remove_reference<Stream>::type next_layer_type;
00066
00068 typedef typename next_layer_type::lowest_layer_type lowest_layer_type;
00069
00071 typedef Service service_type;
00072
00074 typedef typename service_type::impl_type impl_type;
00075
00077
00085 template <typename Arg, typename Context_Service>
00086 explicit stream(Arg& arg, basic_context<Context_Service>& context)
00087 : next_layer_(arg),
00088 service_(asio::use_service<Service>(next_layer_.io_service())),
00089 impl_(service_.null())
00090 {
00091 service_.create(impl_, next_layer_, context);
00092 }
00093
00095 ~stream()
00096 {
00097 service_.destroy(impl_, next_layer_);
00098 }
00099
00101
00108 asio::io_service& io_service()
00109 {
00110 return next_layer_.io_service();
00111 }
00112
00114
00121 next_layer_type& next_layer()
00122 {
00123 return next_layer_;
00124 }
00125
00127
00134 lowest_layer_type& lowest_layer()
00135 {
00136 return next_layer_.lowest_layer();
00137 }
00138
00140
00145 impl_type impl()
00146 {
00147 return impl_;
00148 }
00149
00151
00160 void handshake(handshake_type type)
00161 {
00162 asio::error_code ec;
00163 service_.handshake(impl_, next_layer_, type, ec);
00164 asio::detail::throw_error(ec);
00165 }
00166
00168
00177 asio::error_code handshake(handshake_type type,
00178 asio::error_code& ec)
00179 {
00180 return service_.handshake(impl_, next_layer_, type, ec);
00181 }
00182
00184
00198 template <typename HandshakeHandler>
00199 void async_handshake(handshake_type type, HandshakeHandler handler)
00200 {
00201 service_.async_handshake(impl_, next_layer_, type, handler);
00202 }
00203
00205
00211 void shutdown()
00212 {
00213 asio::error_code ec;
00214 service_.shutdown(impl_, next_layer_, ec);
00215 asio::detail::throw_error(ec);
00216 }
00217
00219
00225 asio::error_code shutdown(asio::error_code& ec)
00226 {
00227 return service_.shutdown(impl_, next_layer_, ec);
00228 }
00229
00231
00242 template <typename ShutdownHandler>
00243 void async_shutdown(ShutdownHandler handler)
00244 {
00245 service_.async_shutdown(impl_, next_layer_, handler);
00246 }
00247
00249
00264 template <typename ConstBufferSequence>
00265 std::size_t write_some(const ConstBufferSequence& buffers)
00266 {
00267 asio::error_code ec;
00268 std::size_t s = service_.write_some(impl_, next_layer_, buffers, ec);
00269 asio::detail::throw_error(ec);
00270 return s;
00271 }
00272
00274
00289 template <typename ConstBufferSequence>
00290 std::size_t write_some(const ConstBufferSequence& buffers,
00291 asio::error_code& ec)
00292 {
00293 return service_.write_some(impl_, next_layer_, buffers, ec);
00294 }
00295
00297
00318 template <typename ConstBufferSequence, typename WriteHandler>
00319 void async_write_some(const ConstBufferSequence& buffers,
00320 WriteHandler handler)
00321 {
00322 service_.async_write_some(impl_, next_layer_, buffers, handler);
00323 }
00324
00326
00341 template <typename MutableBufferSequence>
00342 std::size_t read_some(const MutableBufferSequence& buffers)
00343 {
00344 asio::error_code ec;
00345 std::size_t s = service_.read_some(impl_, next_layer_, buffers, ec);
00346 asio::detail::throw_error(ec);
00347 return s;
00348 }
00349
00351
00366 template <typename MutableBufferSequence>
00367 std::size_t read_some(const MutableBufferSequence& buffers,
00368 asio::error_code& ec)
00369 {
00370 return service_.read_some(impl_, next_layer_, buffers, ec);
00371 }
00372
00374
00396 template <typename MutableBufferSequence, typename ReadHandler>
00397 void async_read_some(const MutableBufferSequence& buffers,
00398 ReadHandler handler)
00399 {
00400 service_.async_read_some(impl_, next_layer_, buffers, handler);
00401 }
00402
00404
00415 template <typename MutableBufferSequence>
00416 std::size_t peek(const MutableBufferSequence& buffers)
00417 {
00418 asio::error_code ec;
00419 std::size_t s = service_.peek(impl_, next_layer_, buffers, ec);
00420 asio::detail::throw_error(ec);
00421 return s;
00422 }
00423
00425
00436 template <typename MutableBufferSequence>
00437 std::size_t peek(const MutableBufferSequence& buffers,
00438 asio::error_code& ec)
00439 {
00440 return service_.peek(impl_, next_layer_, buffers, ec);
00441 }
00442
00444
00452 std::size_t in_avail()
00453 {
00454 asio::error_code ec;
00455 std::size_t s = service_.in_avail(impl_, next_layer_, ec);
00456 asio::detail::throw_error(ec);
00457 return s;
00458 }
00459
00461
00469 std::size_t in_avail(asio::error_code& ec)
00470 {
00471 return service_.in_avail(impl_, next_layer_, ec);
00472 }
00473
00474 private:
00476 Stream next_layer_;
00477
00479 service_type& service_;
00480
00482 impl_type impl_;
00483 };
00484
00485 }
00486 }
00487
00488 #include "asio/detail/pop_options.hpp"
00489
00490 #endif // ASIO_SSL_STREAM_HPP