Realistic 3D camera system
3D camera system components
stream.hpp
Go to the documentation of this file.
1 //
2 // ssl/stream.hpp
3 // ~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //
10 
11 #ifndef ASIO_SSL_STREAM_HPP
12 #define ASIO_SSL_STREAM_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include "asio/detail/config.hpp"
19 
20 #if defined(ASIO_ENABLE_OLD_SSL)
21 # include "asio/ssl/old/stream.hpp"
22 #else // defined(ASIO_ENABLE_OLD_SSL)
23 # include "asio/async_result.hpp"
28 # include "asio/ssl/context.hpp"
31 # include "asio/ssl/detail/io.hpp"
36 # include "asio/ssl/stream_base.hpp"
37 #endif // defined(ASIO_ENABLE_OLD_SSL)
38 
40 
41 namespace asio {
42 namespace ssl {
43 
44 #if defined(ASIO_ENABLE_OLD_SSL)
45 
47 
48 #else // defined(ASIO_ENABLE_OLD_SSL)
49 
51 
72 template <typename Stream>
73 class stream :
74  public stream_base,
75  private noncopyable
76 {
77 public:
79  typedef SSL* native_handle_type;
80 
82  struct impl_struct
83  {
84  SSL* ssl;
85  };
86 
88  typedef impl_struct* impl_type;
89 
91  typedef typename remove_reference<Stream>::type next_layer_type;
92 
94  typedef typename next_layer_type::lowest_layer_type lowest_layer_type;
95 
97 
105  template <typename Arg>
106  stream(Arg& arg, context& ctx)
107  : next_layer_(arg),
108  core_(ctx.native_handle(), next_layer_.lowest_layer().get_io_service())
109  {
110  backwards_compatible_impl_.ssl = core_.engine_.native_handle();
111  }
112 
115  {
116  }
117 
119 
127  {
128  return next_layer_.lowest_layer().get_io_service();
129  }
130 
132 
155  native_handle_type native_handle()
156  {
157  return core_.engine_.native_handle();
158  }
159 
162 
167  impl_type impl()
168  {
169  return &backwards_compatible_impl_;
170  }
171 
173 
180  const next_layer_type& next_layer() const
181  {
182  return next_layer_;
183  }
184 
186 
193  next_layer_type& next_layer()
194  {
195  return next_layer_;
196  }
197 
199 
206  lowest_layer_type& lowest_layer()
207  {
208  return next_layer_.lowest_layer();
209  }
210 
212 
219  const lowest_layer_type& lowest_layer() const
220  {
221  return next_layer_.lowest_layer();
222  }
223 
225 
237  {
238  asio::error_code ec;
239  set_verify_mode(v, ec);
240  asio::detail::throw_error(ec, "set_verify_mode");
241  }
242 
244 
257  {
258  return core_.engine_.set_verify_mode(v, ec);
259  }
260 
262 
273  void set_verify_depth(int depth)
274  {
275  asio::error_code ec;
276  set_verify_depth(depth, ec);
277  asio::detail::throw_error(ec, "set_verify_depth");
278  }
279 
281 
293  int depth, asio::error_code& ec)
294  {
295  return core_.engine_.set_verify_depth(depth, ec);
296  }
297 
299 
316  template <typename VerifyCallback>
317  void set_verify_callback(VerifyCallback callback)
318  {
319  asio::error_code ec;
320  this->set_verify_callback(callback, ec);
321  asio::detail::throw_error(ec, "set_verify_callback");
322  }
323 
325 
342  template <typename VerifyCallback>
343  asio::error_code set_verify_callback(VerifyCallback callback,
344  asio::error_code& ec)
345  {
346  return core_.engine_.set_verify_callback(
347  new detail::verify_callback<VerifyCallback>(callback), ec);
348  }
349 
351 
361  {
362  asio::error_code ec;
363  handshake(type, ec);
364  asio::detail::throw_error(ec, "handshake");
365  }
366 
368 
378  asio::error_code& ec)
379  {
380  detail::io(next_layer_, core_, detail::handshake_op(type), ec);
381  return ec;
382  }
383 
385 
396  template <typename ConstBufferSequence>
397  void handshake(handshake_type type, const ConstBufferSequence& buffers)
398  {
399  asio::error_code ec;
400  handshake(type, buffers, ec);
401  asio::detail::throw_error(ec, "handshake");
402  }
403 
405 
416  template <typename ConstBufferSequence>
418  const ConstBufferSequence& buffers, asio::error_code& ec)
419  {
420  detail::io(next_layer_, core_,
422  return ec;
423  }
424 
426 
440  template <typename HandshakeHandler>
441  ASIO_INITFN_RESULT_TYPE(HandshakeHandler,
442  void (asio::error_code))
443  async_handshake(handshake_type type,
444  ASIO_MOVE_ARG(HandshakeHandler) handler)
445  {
446  // If you get an error on the following line it means that your handler does
447  // not meet the documented type requirements for a HandshakeHandler.
448  ASIO_HANDSHAKE_HANDLER_CHECK(HandshakeHandler, handler) type_check;
449 
451  HandshakeHandler, void (asio::error_code)> init(
452  ASIO_MOVE_CAST(HandshakeHandler)(handler));
453 
454  detail::async_io(next_layer_, core_,
455  detail::handshake_op(type), init.handler);
456 
457  return init.result.get();
458  }
459 
461 
481  template <typename ConstBufferSequence, typename BufferedHandshakeHandler>
482  ASIO_INITFN_RESULT_TYPE(BufferedHandshakeHandler,
483  void (asio::error_code, std::size_t))
484  async_handshake(handshake_type type, const ConstBufferSequence& buffers,
485  ASIO_MOVE_ARG(BufferedHandshakeHandler) handler)
486  {
487  // If you get an error on the following line it means that your handler does
488  // not meet the documented type requirements for a BufferedHandshakeHandler.
490  BufferedHandshakeHandler, handler) type_check;
491 
492  asio::detail::async_result_init<BufferedHandshakeHandler,
493  void (asio::error_code, std::size_t)> init(
494  ASIO_MOVE_CAST(BufferedHandshakeHandler)(handler));
495 
496  detail::async_io(next_layer_, core_,
498  init.handler);
499 
500  return init.result.get();
501  }
502 
504 
510  void shutdown()
511  {
512  asio::error_code ec;
513  shutdown(ec);
514  asio::detail::throw_error(ec, "shutdown");
515  }
516 
518 
525  {
526  detail::io(next_layer_, core_, detail::shutdown_op(), ec);
527  return ec;
528  }
529 
531 
542  template <typename ShutdownHandler>
543  ASIO_INITFN_RESULT_TYPE(ShutdownHandler,
544  void (asio::error_code))
545  async_shutdown(ASIO_MOVE_ARG(ShutdownHandler) handler)
546  {
547  // If you get an error on the following line it means that your handler does
548  // not meet the documented type requirements for a ShutdownHandler.
549  ASIO_SHUTDOWN_HANDLER_CHECK(ShutdownHandler, handler) type_check;
550 
552  ShutdownHandler, void (asio::error_code)> init(
553  ASIO_MOVE_CAST(ShutdownHandler)(handler));
554 
555  detail::async_io(next_layer_, core_, detail::shutdown_op(), init.handler);
556 
557  return init.result.get();
558  }
559 
561 
576  template <typename ConstBufferSequence>
577  std::size_t write_some(const ConstBufferSequence& buffers)
578  {
579  asio::error_code ec;
580  std::size_t n = write_some(buffers, ec);
581  asio::detail::throw_error(ec, "write_some");
582  return n;
583  }
584 
586 
601  template <typename ConstBufferSequence>
602  std::size_t write_some(const ConstBufferSequence& buffers,
603  asio::error_code& ec)
604  {
605  return detail::io(next_layer_, core_,
607  }
608 
610 
631  template <typename ConstBufferSequence, typename WriteHandler>
632  ASIO_INITFN_RESULT_TYPE(WriteHandler,
633  void (asio::error_code, std::size_t))
634  async_write_some(const ConstBufferSequence& buffers,
635  ASIO_MOVE_ARG(WriteHandler) handler)
636  {
637  // If you get an error on the following line it means that your handler does
638  // not meet the documented type requirements for a WriteHandler.
639  ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
640 
642  WriteHandler, void (asio::error_code, std::size_t)> init(
643  ASIO_MOVE_CAST(WriteHandler)(handler));
644 
645  detail::async_io(next_layer_, core_,
647 
648  return init.result.get();
649  }
650 
652 
667  template <typename MutableBufferSequence>
668  std::size_t read_some(const MutableBufferSequence& buffers)
669  {
670  asio::error_code ec;
671  std::size_t n = read_some(buffers, ec);
672  asio::detail::throw_error(ec, "read_some");
673  return n;
674  }
675 
677 
692  template <typename MutableBufferSequence>
693  std::size_t read_some(const MutableBufferSequence& buffers,
694  asio::error_code& ec)
695  {
696  return detail::io(next_layer_, core_,
698  }
699 
701 
723  template <typename MutableBufferSequence, typename ReadHandler>
724  ASIO_INITFN_RESULT_TYPE(ReadHandler,
725  void (asio::error_code, std::size_t))
726  async_read_some(const MutableBufferSequence& buffers,
727  ASIO_MOVE_ARG(ReadHandler) handler)
728  {
729  // If you get an error on the following line it means that your handler does
730  // not meet the documented type requirements for a ReadHandler.
731  ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
732 
734  ReadHandler, void (asio::error_code, std::size_t)> init(
735  ASIO_MOVE_CAST(ReadHandler)(handler));
736 
737  detail::async_io(next_layer_, core_,
739 
740  return init.result.get();
741  }
742 
743 private:
744  Stream next_layer_;
745  detail::stream_core core_;
746  impl_struct backwards_compatible_impl_;
747 };
748 
749 #endif // defined(ASIO_ENABLE_OLD_SSL)
750 
751 } // namespace ssl
752 } // namespace asio
753 
755 
756 #endif // ASIO_SSL_STREAM_HPP
asio::error_code handshake(handshake_type type, asio::error_code &ec)
Perform SSL handshaking.
Definition: stream.hpp:377
Structure for use with deprecated impl_type.
Definition: stream.hpp:82
void throw_error(const asio::error_code &err)
Definition: throw_error.hpp:31
ASIO_MOVE_ARG(WriteHandler) handler)
Definition: stream.hpp:635
void async_io(Stream &next_layer, stream_core &core, const Operation &op, Handler &handler)
Definition: io.hpp:333
void set_verify_mode(verify_mode v)
Set the peer verification mode.
Definition: stream.hpp:236
ASIO_INITFN_RESULT_TYPE(ShutdownHandler, void(asio::error_code)) async_shutdown(ASIO_MOVE_ARG(ShutdownHandler) handler)
Asynchronously shut down SSL on the stream.
Definition: stream.hpp:543
Provides core I/O functionality.
Definition: io_service.hpp:184
void set_verify_callback(VerifyCallback callback)
Set the callback used to verify peer certificates.
Definition: stream.hpp:317
~stream()
Destructor.
Definition: stream.hpp:114
asio::error_code set_verify_callback(VerifyCallback callback, asio::error_code &ec)
Set the callback used to verify peer certificates.
Definition: stream.hpp:343
asio::basic_streambuf< Allocator > MatchCondition enable_if< is_match_condition< MatchCondition >::value >::type *detail::async_result_init< ReadHandler, void(asio::error_code, std::size_t)> init(ASIO_MOVE_CAST(ReadHandler)(handler))
Provides stream-oriented functionality using SSL.
Definition: stream.hpp:56
native_handle_type native_handle()
Get the underlying implementation in the native type.
Definition: stream.hpp:155
void shutdown()
Shut down SSL on the stream.
Definition: stream.hpp:510
const ConstBufferSequence & buffers
Definition: stream.hpp:484
#define ASIO_BUFFERED_HANDSHAKE_HANDLER_CHECK(handler_type, handler)
std::size_t io(Stream &next_layer, stream_core &core, const Operation &op, asio::error_code &ec)
Definition: io.hpp:35
void set_verify_depth(int depth)
Set the peer verification depth.
Definition: stream.hpp:273
void handshake(handshake_type type, const ConstBufferSequence &buffers)
Perform SSL handshaking.
Definition: stream.hpp:397
next_layer_type & next_layer()
Get a reference to the next layer.
Definition: stream.hpp:193
handshake_type
Different handshake types.
Definition: stream_base.hpp:31
#define ASIO_READ_HANDLER_CHECK(handler_type, handler)
impl_type impl()
Definition: stream.hpp:167
asio::error_code set_verify_mode(verify_mode v, asio::error_code &ec)
Set the peer verification mode.
Definition: stream.hpp:255
int verify_mode
Bitmask type for peer verification.
Definition: verify_mode.hpp:35
std::size_t read_some(const MutableBufferSequence &buffers)
Read some data from the stream.
Definition: stream.hpp:668
ASIO_MOVE_ARG(HandshakeHandler) handler)
Definition: stream.hpp:444
const lowest_layer_type & lowest_layer() const
Get a reference to the lowest layer.
Definition: stream.hpp:219
const next_layer_type & next_layer() const
Get a reference to the next layer.
Definition: stream.hpp:180
#define ASIO_SHUTDOWN_HANDLER_CHECK(handler_type, handler)
ASIO_INITFN_RESULT_TYPE(HandshakeHandler, void(asio::error_code)) async_handshake(handshake_type type
Start an asynchronous SSL handshake.
ASIO_MOVE_ARG(ReadHandler) handler)
Definition: stream.hpp:727
#define ASIO_HANDSHAKE_HANDLER_CHECK(handler_type, handler)
impl_struct * impl_type
(Deprecated: Use native_handle_type.) The underlying implementation type.
Definition: stream.hpp:88
next_layer_type::lowest_layer_type lowest_layer_type
The type of the lowest layer.
Definition: stream.hpp:94
stream(Arg &arg, context &ctx)
Construct a stream.
Definition: stream.hpp:106
Class to represent an error code value.
Definition: error_code.hpp:80
asio::error_code handshake(handshake_type type, const ConstBufferSequence &buffers, asio::error_code &ec)
Perform SSL handshaking.
Definition: stream.hpp:417
SSL * native_handle_type
The native handle type of the SSL stream.
Definition: stream.hpp:79
lowest_layer_type & lowest_layer()
Get a reference to the lowest layer.
Definition: stream.hpp:206
void handshake(handshake_type type)
Perform SSL handshaking.
Definition: stream.hpp:360
handler_type< Handler, Signature >::type handler
Provides stream-oriented functionality using SSL.
Definition: stream.hpp:73
#define ASIO_MOVE_CAST(type)
Definition: config.hpp:138
asio::error_code shutdown(asio::error_code &ec)
Shut down SSL on the stream.
Definition: stream.hpp:524
async_result< typename handler_type< Handler, Signature >::type > result
std::size_t read_some(const MutableBufferSequence &buffers, asio::error_code &ec)
Read some data from the stream.
Definition: stream.hpp:693
#define ASIO_WRITE_HANDLER_CHECK(handler_type, handler)
remove_reference< Stream >::type next_layer_type
The type of the next layer.
Definition: stream.hpp:91
std::size_t write_some(const ConstBufferSequence &buffers, asio::error_code &ec)
Write some data to the stream.
Definition: stream.hpp:602
std::size_t write_some(const ConstBufferSequence &buffers)
Write some data to the stream.
Definition: stream.hpp:577
asio::io_service & get_io_service()
Get the io_service associated with the object.
Definition: stream.hpp:126
asio::error_code set_verify_depth(int depth, asio::error_code &ec)
Set the peer verification depth.
Definition: stream.hpp:292