Realistic 3D camera system
3D camera system components
openssl_init.hpp
Go to the documentation of this file.
1 //
2 // ssl/detail/openssl_init.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_DETAIL_OPENSSL_INIT_HPP
12 #define ASIO_SSL_DETAIL_OPENSSL_INIT_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 #include <cstring>
23 
25 
26 namespace asio {
27 namespace ssl {
28 namespace detail {
29 
31  : private noncopyable
32 {
33 protected:
34  // Class that performs the actual initialisation.
35  class do_init;
36 
37  // Helper function to manage a do_init singleton. The static instance of the
38  // openssl_init object ensures that this function is always called before
39  // main, and therefore before any other threads can get started. The do_init
40  // instance must be static in this function to ensure that it gets
41  // initialised before any other global objects try to use it.
42  ASIO_DECL static asio::detail::shared_ptr<do_init> instance();
43 
44 #if !defined(SSL_OP_NO_COMPRESSION) \
45  && (OPENSSL_VERSION_NUMBER >= 0x00908000L)
46  // Get an empty stack of compression methods, to be used when disabling
47  // compression.
48  ASIO_DECL static STACK_OF(SSL_COMP)* get_null_compression_methods();
49 #endif // !defined(SSL_OP_NO_COMPRESSION)
50  // && (OPENSSL_VERSION_NUMBER >= 0x00908000L)
51 };
52 
53 template <bool Do_Init = true>
55 {
56 public:
57  // Constructor.
59  : ref_(instance())
60  {
61  using namespace std; // For memmove.
62 
63  // Ensure openssl_init::instance_ is linked in.
64  openssl_init* tmp = &instance_;
65  memmove(&tmp, &tmp, sizeof(openssl_init*));
66  }
67 
68  // Destructor.
70  {
71  }
72 
73 #if !defined(SSL_OP_NO_COMPRESSION) \
74  && (OPENSSL_VERSION_NUMBER >= 0x00908000L)
75  using openssl_init_base::get_null_compression_methods;
76 #endif // !defined(SSL_OP_NO_COMPRESSION)
77  // && (OPENSSL_VERSION_NUMBER >= 0x00908000L)
78 
79 private:
80  // Instance to force initialisation of openssl at global scope.
81  static openssl_init instance_;
82 
83  // Reference to singleton do_init object to ensure that openssl does not get
84  // cleaned up until the last user has finished with it.
85  asio::detail::shared_ptr<do_init> ref_;
86 };
87 
88 template <bool Do_Init>
90 
91 } // namespace detail
92 } // namespace ssl
93 } // namespace asio
94 
96 
97 #if defined(ASIO_HEADER_ONLY)
99 #endif // defined(ASIO_HEADER_ONLY)
100 
101 #endif // ASIO_SSL_DETAIL_OPENSSL_INIT_HPP
static ASIO_DECL asio::detail::shared_ptr< do_init > instance()
STL namespace.
#define ASIO_DECL
Definition: config.hpp:43