/***************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * $Id$ * * A multi-threaded example that uses pthreads and fetches 4 remote files at * once over HTTPS. The lock callbacks and stuff assume OpenSSL so far. * Should be expanded to do optional GnuTLS style locking. * * OpenSSL docs for this: http://www.openssl.org/docs/crypto/threads.html */ #include #include #include #include /* we have this global to let the callback get easy access to it */ static pthread_mutex_t *lockarray; static void lock_callback(int mode, int type, char *file, int line) { (void)file; (void)line; if (mode & CRYPTO_LOCK) { pthread_mutex_lock(&(lockarray[type])); } else { pthread_mutex_unlock(&(lockarray[type])); } } static unsigned long thread_id(void) { unsigned long ret; ret=(unsigned long)pthread_self(); return(ret); } static void init_locks(void) { int i; lockarray=(pthread_mutex_t *)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t)); for (i=0; i