diff --git a/Source/GSSocketStream.m b/Source/GSSocketStream.m index bc5d40de3..558d233aa 100644 --- a/Source/GSSocketStream.m +++ b/Source/GSSocketStream.m @@ -32,6 +32,7 @@ #import #import #import +#import #import #import @@ -40,7 +41,44 @@ #import "GSPrivate.h" #if defined(HAVE_GNUTLS) -#include +#include +#include +#endif + +#undef HAVE_PTHREAD_H +#ifdef HAVE_PTHREAD_H +#include +GCRY_THREAD_OPTION_PTHREAD_IMPL; +#else +static int gcry_mutex_init (void **priv) +{ + NSLock *lock = [NSLock new]; + *priv = (void*)lock; + return 0; +} +static int gcry_mutex_destroy (void **lock) +{ + [((NSLock*)*lock) release]; + return 0; +} +static int gcry_mutex_lock (void **lock) +{ + [((NSLock*)*lock) lock]; + return 0; +} +static int gcry_mutex_unlock (void **lock) +{ + [((NSLock*)*lock) unlock]; + return 0; +} +static struct gcry_thread_cbs gcry_threads_other = { + GCRY_THREAD_OPTION_DEFAULT, + NULL, + gcry_mutex_init, + gcry_mutex_destroy, + gcry_mutex_lock, + gcry_mutex_unlock +}; #endif @interface GSTLS : NSObject @@ -139,6 +177,12 @@ static gnutls_anon_client_credentials_t anoncred; if (beenHere == NO) { beenHere = YES; + +#ifdef HAVE_PTHREAD_H + gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); +#else + gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_other); +#endif gnutls_global_init (); gnutls_anon_allocate_client_credentials (&anoncred); gnutls_global_set_log_function (GSTLSLog);