Differences From Artifact [5dc22a018c]:
- File src/SSLSocket.m — part of check-in [87c3eab6d6] at 2012-09-20 00:14:04 on branch trunk — Adjust to latest ObjFW changes. (user: js, size: 10104) [annotate] [blame] [check-ins using]
To Artifact [0345d05eb1]:
- File
src/SSLSocket.m
— part of check-in
[3062d2861f]
at
2012-11-08 13:19:44
on branch trunk
— 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. (user: js, size: 10225) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
22 23 24 25 26 27 28 | * POSSIBILITY OF SUCH DAMAGE. */ #include <unistd.h> #include <errno.h> #include <assert.h> | < < < | | | > > > > > > > > > > | | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | * POSSIBILITY OF SUCH DAMAGE. */ #include <unistd.h> #include <errno.h> #include <assert.h> #include <openssl/crypto.h> #include <openssl/err.h> #import <ObjFW/OFThread.h> #import <ObjFW/OFHTTPRequest.h> #import <ObjFW/OFDataArray.h> #import <ObjFW/OFAcceptFailedException.h> #import <ObjFW/OFConnectionFailedException.h> #import <ObjFW/OFInitializationFailedException.h> #import <ObjFW/OFInvalidArgumentException.h> #import <ObjFW/OFNotConnectedException.h> #import <ObjFW/OFOutOfRangeException.h> #import <ObjFW/OFReadFailedException.h> #import <ObjFW/OFWriteFailedException.h> #import <ObjFW/macros.h> #import <ObjFW/threading.h> #import "SSLSocket.h" #import "SSLInvalidCertificateException.h" #import "X509Certificate.h" #ifndef INVALID_SOCKET # define INVALID_SOCKET -1 #endif 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 locking_callback(int mode, int n, const char *file, int line) { /* * This function must handle up to CRYPTO_num_locks() mutexes. * It must set the n-th lock if mode & CRYPTO_LOCK, * release it otherwise. */ if (mode & CRYPTO_LOCK) |
︙ | ︙ | |||
77 78 79 80 81 82 83 | + (void)initialize { int m; if (self != [SSLSocket class]) return; | | | | 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | + (void)initialize { int m; if (self != [SSLSocket class]) return; CRYPTO_set_id_callback(&get_thread_id); /* Generate number of mutexes needed */ m = CRYPTO_num_locks(); ssl_mutexes = malloc(m * sizeof(of_mutex_t)); for (m--; m >= 0; m--) of_mutex_new(&ssl_mutexes[m]); CRYPTO_set_locking_callback(&locking_callback); SSL_library_init(); if ((ctx = SSL_CTX_new(SSLv23_method())) == NULL) @throw [OFInitializationFailedException exceptionWithClass: self]; |
︙ | ︙ |