stream_core.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // ssl/detail/stream_core.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 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. #ifndef BOOST_ASIO_SSL_DETAIL_STREAM_CORE_HPP
  11. #define BOOST_ASIO_SSL_DETAIL_STREAM_CORE_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
  17. # include <boost/asio/deadline_timer.hpp>
  18. #else // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
  19. # include <boost/asio/steady_timer.hpp>
  20. #endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
  21. #include <boost/asio/ssl/detail/engine.hpp>
  22. #include <boost/asio/buffer.hpp>
  23. #include <boost/asio/detail/push_options.hpp>
  24. namespace boost {
  25. namespace asio {
  26. namespace ssl {
  27. namespace detail {
  28. struct stream_core
  29. {
  30. // According to the OpenSSL documentation, this is the buffer size that is
  31. // sufficient to hold the largest possible TLS record.
  32. enum { max_tls_record_size = 17 * 1024 };
  33. template <typename Executor>
  34. stream_core(SSL_CTX* context, const Executor& ex)
  35. : engine_(context),
  36. pending_read_(ex),
  37. pending_write_(ex),
  38. output_buffer_space_(max_tls_record_size),
  39. output_buffer_(boost::asio::buffer(output_buffer_space_)),
  40. input_buffer_space_(max_tls_record_size),
  41. input_buffer_(boost::asio::buffer(input_buffer_space_))
  42. {
  43. pending_read_.expires_at(neg_infin());
  44. pending_write_.expires_at(neg_infin());
  45. }
  46. ~stream_core()
  47. {
  48. }
  49. // The SSL engine.
  50. engine engine_;
  51. #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
  52. // Timer used for storing queued read operations.
  53. boost::asio::deadline_timer pending_read_;
  54. // Timer used for storing queued write operations.
  55. boost::asio::deadline_timer pending_write_;
  56. // Helper function for obtaining a time value that always fires.
  57. static boost::asio::deadline_timer::time_type neg_infin()
  58. {
  59. return boost::posix_time::neg_infin;
  60. }
  61. // Helper function for obtaining a time value that never fires.
  62. static boost::asio::deadline_timer::time_type pos_infin()
  63. {
  64. return boost::posix_time::pos_infin;
  65. }
  66. // Helper function to get a timer's expiry time.
  67. static boost::asio::deadline_timer::time_type expiry(
  68. const boost::asio::deadline_timer& timer)
  69. {
  70. return timer.expires_at();
  71. }
  72. #else // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
  73. // Timer used for storing queued read operations.
  74. boost::asio::steady_timer pending_read_;
  75. // Timer used for storing queued write operations.
  76. boost::asio::steady_timer pending_write_;
  77. // Helper function for obtaining a time value that always fires.
  78. static boost::asio::steady_timer::time_point neg_infin()
  79. {
  80. return (boost::asio::steady_timer::time_point::min)();
  81. }
  82. // Helper function for obtaining a time value that never fires.
  83. static boost::asio::steady_timer::time_point pos_infin()
  84. {
  85. return (boost::asio::steady_timer::time_point::max)();
  86. }
  87. // Helper function to get a timer's expiry time.
  88. static boost::asio::steady_timer::time_point expiry(
  89. const boost::asio::steady_timer& timer)
  90. {
  91. return timer.expiry();
  92. }
  93. #endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
  94. // Buffer space used to prepare output intended for the transport.
  95. std::vector<unsigned char> output_buffer_space_;
  96. // A buffer that may be used to prepare output intended for the transport.
  97. const boost::asio::mutable_buffer output_buffer_;
  98. // Buffer space used to read input intended for the engine.
  99. std::vector<unsigned char> input_buffer_space_;
  100. // A buffer that may be used to read input intended for the engine.
  101. const boost::asio::mutable_buffer input_buffer_;
  102. // The buffer pointing to the engine's unconsumed input.
  103. boost::asio::const_buffer input_;
  104. };
  105. } // namespace detail
  106. } // namespace ssl
  107. } // namespace asio
  108. } // namespace boost
  109. #include <boost/asio/detail/pop_options.hpp>
  110. #endif // BOOST_ASIO_SSL_DETAIL_STREAM_CORE_HPP