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.
This commit is contained in:
parent
02478205c7
commit
ce3b9a11cd
1 changed files with 16 additions and 9 deletions
|
@ -26,15 +26,12 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#import <ObjFW/OFHTTPRequest.h>
|
|
||||||
#import <ObjFW/OFDataArray.h>
|
|
||||||
|
|
||||||
#include <openssl/crypto.h>
|
#include <openssl/crypto.h>
|
||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
|
|
||||||
#import "SSLSocket.h"
|
#import <ObjFW/OFThread.h>
|
||||||
#import "SSLInvalidCertificateException.h"
|
#import <ObjFW/OFHTTPRequest.h>
|
||||||
#import "X509Certificate.h"
|
#import <ObjFW/OFDataArray.h>
|
||||||
|
|
||||||
#import <ObjFW/OFAcceptFailedException.h>
|
#import <ObjFW/OFAcceptFailedException.h>
|
||||||
#import <ObjFW/OFConnectionFailedException.h>
|
#import <ObjFW/OFConnectionFailedException.h>
|
||||||
|
@ -47,6 +44,10 @@
|
||||||
#import <ObjFW/macros.h>
|
#import <ObjFW/macros.h>
|
||||||
#import <ObjFW/threading.h>
|
#import <ObjFW/threading.h>
|
||||||
|
|
||||||
|
#import "SSLSocket.h"
|
||||||
|
#import "SSLInvalidCertificateException.h"
|
||||||
|
#import "X509Certificate.h"
|
||||||
|
|
||||||
#ifndef INVALID_SOCKET
|
#ifndef INVALID_SOCKET
|
||||||
# define INVALID_SOCKET -1
|
# define INVALID_SOCKET -1
|
||||||
#endif
|
#endif
|
||||||
|
@ -54,8 +55,14 @@
|
||||||
static SSL_CTX *ctx;
|
static SSL_CTX *ctx;
|
||||||
static of_mutex_t *ssl_mutexes;
|
static of_mutex_t *ssl_mutexes;
|
||||||
|
|
||||||
|
static unsigned long
|
||||||
|
get_thread_id(void)
|
||||||
|
{
|
||||||
|
return (unsigned long)(uintptr_t)[OFThread currentThread];
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
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.
|
* 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])
|
if (self != [SSLSocket class])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CRYPTO_set_id_callback(&of_thread_current);
|
CRYPTO_set_id_callback(&get_thread_id);
|
||||||
|
|
||||||
/* Generate number of mutexes needed */
|
/* Generate number of mutexes needed */
|
||||||
m = CRYPTO_num_locks();
|
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--)
|
for (m--; m >= 0; m--)
|
||||||
of_mutex_new(&ssl_mutexes[m]);
|
of_mutex_new(&ssl_mutexes[m]);
|
||||||
|
|
||||||
CRYPTO_set_locking_callback(&ssl_locking_callback);
|
CRYPTO_set_locking_callback(&locking_callback);
|
||||||
|
|
||||||
SSL_library_init();
|
SSL_library_init();
|
||||||
|
|
||||||
|
|
Reference in a new issue