From ce3b9a11cd45c6139ef8785577a28d1fc28ff51c Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Thu, 8 Nov 2012 12:40:51 +0100 Subject: [PATCH] Use the thread object's address as thread id. This at least works inside OFThreads. The previous solution to use a pthread_t was not portable, as on many systems, pthread_t is a struct. --- src/SSLSocket.m | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/SSLSocket.m b/src/SSLSocket.m index edeffd1..1d5c90f 100644 --- a/src/SSLSocket.m +++ b/src/SSLSocket.m @@ -26,15 +26,12 @@ #include #include -#import -#import - #include #include -#import "SSLSocket.h" -#import "SSLInvalidCertificateException.h" -#import "X509Certificate.h" +#import +#import +#import #import #import @@ -47,6 +44,10 @@ #import #import +#import "SSLSocket.h" +#import "SSLInvalidCertificateException.h" +#import "X509Certificate.h" + #ifndef INVALID_SOCKET # define INVALID_SOCKET -1 #endif @@ -54,8 +55,14 @@ static SSL_CTX *ctx; static of_mutex_t *ssl_mutexes; +static unsigned long +get_thread_id(void) +{ + return (unsigned long)(uintptr_t)[OFThread currentThread]; +} + static void -ssl_locking_callback(int mode, int n, const char *file, int line) +locking_callback(int mode, int n, const char *file, int line) { /* * This function must handle up to CRYPTO_num_locks() mutexes. @@ -81,7 +88,7 @@ ssl_locking_callback(int mode, int n, const char *file, int line) if (self != [SSLSocket class]) return; - CRYPTO_set_id_callback(&of_thread_current); + CRYPTO_set_id_callback(&get_thread_id); /* Generate number of mutexes needed */ m = CRYPTO_num_locks(); @@ -89,7 +96,7 @@ ssl_locking_callback(int mode, int n, const char *file, int line) for (m--; m >= 0; m--) of_mutex_new(&ssl_mutexes[m]); - CRYPTO_set_locking_callback(&ssl_locking_callback); + CRYPTO_set_locking_callback(&locking_callback); SSL_library_init();