From 6e5b3895296a2e01490a6a8a0d73977d7917ffe2 Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Mon, 28 Mar 2011 23:38:09 +0200 Subject: [PATCH] Have one global ctx. --- src/SSLSocket.h | 2 -- src/SSLSocket.m | 29 +++++++++-------------------- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src/SSLSocket.h b/src/SSLSocket.h index 761f641..b7f494d 100644 --- a/src/SSLSocket.h +++ b/src/SSLSocket.h @@ -4,9 +4,7 @@ @interface SSLSocket: OFTCPSocket { - SSL_CTX *ctx; SSL *ssl; - BOOL handsShaken; } - initWithSocket: (OFTCPSocket*)socket; diff --git a/src/SSLSocket.m b/src/SSLSocket.m index 12dea87..732a4fb 100644 --- a/src/SSLSocket.m +++ b/src/SSLSocket.m @@ -18,6 +18,8 @@ # define INVALID_SOCKET -1 #endif +static SSL_CTX *ctx; + @implementation SSLSocket + (void)load { @@ -26,29 +28,16 @@ + (void)initialize { - if (self == [SSLSocket class]) - SSL_library_init(); -} + if (self != [SSLSocket class]) + return; -- init -{ - self = [super init]; + SSL_library_init(); - @try { - if ((ctx = SSL_CTX_new(SSLv23_method())) == NULL) - @throw [OFInitializationFailedException - newWithClass: isa]; + if ((ctx = SSL_CTX_new(SSLv23_method())) == NULL) + @throw [OFInitializationFailedException newWithClass: self]; - if ((SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2) & - SSL_OP_NO_SSLv2) == 0) - @throw [OFInitializationFailedException - newWithClass: isa]; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; + if ((SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2) & SSL_OP_NO_SSLv2) == 0) + @throw [OFInitializationFailedException newWithClass: self]; } - initWithSocket: (OFTCPSocket*)socket