Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
2.9KB

  1. //
  2. // ssl/detail/openssl_init.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 ASIO_SSL_DETAIL_OPENSSL_INIT_HPP
  11. #define ASIO_SSL_DETAIL_OPENSSL_INIT_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #include <cstring>
  17. #include "asio/detail/memory.hpp"
  18. #include "asio/detail/noncopyable.hpp"
  19. #include "asio/ssl/detail/openssl_types.hpp"
  20. #include "asio/detail/push_options.hpp"
  21. namespace asio {
  22. namespace ssl {
  23. namespace detail {
  24. class openssl_init_base
  25. : private noncopyable
  26. {
  27. protected:
  28. // Class that performs the actual initialisation.
  29. class do_init;
  30. // Helper function to manage a do_init singleton. The static instance of the
  31. // openssl_init object ensures that this function is always called before
  32. // main, and therefore before any other threads can get started. The do_init
  33. // instance must be static in this function to ensure that it gets
  34. // initialised before any other global objects try to use it.
  35. ASIO_DECL static asio::detail::shared_ptr<do_init> instance();
  36. #if !defined(SSL_OP_NO_COMPRESSION) \
  37. && (OPENSSL_VERSION_NUMBER >= 0x00908000L)
  38. // Get an empty stack of compression methods, to be used when disabling
  39. // compression.
  40. ASIO_DECL static STACK_OF(SSL_COMP)* get_null_compression_methods();
  41. #endif // !defined(SSL_OP_NO_COMPRESSION)
  42. // && (OPENSSL_VERSION_NUMBER >= 0x00908000L)
  43. };
  44. template <bool Do_Init = true>
  45. class openssl_init : private openssl_init_base
  46. {
  47. public:
  48. // Constructor.
  49. openssl_init()
  50. : ref_(instance())
  51. {
  52. using namespace std; // For memmove.
  53. // Ensure openssl_init::instance_ is linked in.
  54. openssl_init* tmp = &instance_;
  55. memmove(&tmp, &tmp, sizeof(openssl_init*));
  56. }
  57. // Destructor.
  58. ~openssl_init()
  59. {
  60. }
  61. #if !defined(SSL_OP_NO_COMPRESSION) \
  62. && (OPENSSL_VERSION_NUMBER >= 0x00908000L)
  63. using openssl_init_base::get_null_compression_methods;
  64. #endif // !defined(SSL_OP_NO_COMPRESSION)
  65. // && (OPENSSL_VERSION_NUMBER >= 0x00908000L)
  66. private:
  67. // Instance to force initialisation of openssl at global scope.
  68. static openssl_init instance_;
  69. // Reference to singleton do_init object to ensure that openssl does not get
  70. // cleaned up until the last user has finished with it.
  71. asio::detail::shared_ptr<do_init> ref_;
  72. };
  73. template <bool Do_Init>
  74. openssl_init<Do_Init> openssl_init<Do_Init>::instance_;
  75. } // namespace detail
  76. } // namespace ssl
  77. } // namespace asio
  78. #include "asio/detail/pop_options.hpp"
  79. #if defined(ASIO_HEADER_ONLY)
  80. # include "asio/ssl/detail/impl/openssl_init.ipp"
  81. #endif // defined(ASIO_HEADER_ONLY)
  82. #endif // ASIO_SSL_DETAIL_OPENSSL_INIT_HPP