summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Antonuk <aega@med.umich.edu>2012-05-29 16:03:49 -0400
committerAlan Antonuk <aega@med.umich.edu>2012-05-29 16:03:49 -0400
commiteb467fe75ca2de3b3f6fe7e1502166b0916eea2a (patch)
tree503d9d343afc96df2739631912bc6dcf964d6953
parentfab72882d7b033da8612c499c6c30457271dd5e4 (diff)
downloadrabbitmq-c-github-ask-eb467fe75ca2de3b3f6fe7e1502166b0916eea2a.tar.gz
Adding function to init OpenSSL once
-rw-r--r--librabbitmq/amqp-openssl.c35
1 files changed, 32 insertions, 3 deletions
diff --git a/librabbitmq/amqp-openssl.c b/librabbitmq/amqp-openssl.c
index 229e285..d136b70 100644
--- a/librabbitmq/amqp-openssl.c
+++ b/librabbitmq/amqp-openssl.c
@@ -32,6 +32,10 @@
#include <openssl/ssl.h>
#include <stdlib.h>
+static int initialize_openssl();
+static int destroy_openssl();
+
+int open_connections = 0;
amqp_boolean_t do_initialize_openssl = 1;
amqp_boolean_t openssl_initialized = 0;
@@ -141,6 +145,7 @@ amqp_ssl_socket_close(int sockfd,
free(self->buffer);
free(self);
}
+ destroy_openssl();
return 0 > sockfd ? -1 : 0;
}
@@ -167,9 +172,7 @@ amqp_open_ssl_socket(amqp_connection_state_t state,
struct amqp_ssl_socket_context *self;
int sockfd, status, pos, utf8_length;
unsigned char *utf8_value = NULL, *cp, ch;
- SSL_library_init();
- SSL_load_error_strings();
- OpenSSL_add_all_algorithms();
+ initialize_openssl();
self = calloc(1, sizeof(*self));
if (!self) {
goto error;
@@ -282,3 +285,29 @@ amqp_set_initialize_ssl_library(amqp_boolean_t do_initialize)
do_initialize_openssl = do_initialize;
}
}
+
+static int
+initialize_openssl()
+{
+ if (do_initialize_openssl)
+ {
+ if (!openssl_initialized)
+ {
+ OPENSSL_config(NULL);
+
+ SSL_library_init();
+ SSL_load_error_strings();
+
+ openssl_initialized = 1;
+ }
+ }
+
+ ++open_connections;
+ return 0;
+}
+
+static int
+destroy_openssl()
+{
+ --open_connections;
+}