diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 73383131e..16f3152b5 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -33,5 +33,5 @@ noinst_PROGRAMS = 10-at-a-time anyauthput cookie_interface \ COMPLICATED_EXAMPLES = \ curlgtk.c curlx.c htmltitle.cc cacertinmem.c ftpuploadresume.c \ ghiper.c hiperfifo.c htmltidy.c multithread.c \ - opensslthreadlock.c sampleconv.c synctime.c + opensslthreadlock.c sampleconv.c synctime.c threaded-ssl.c diff --git a/docs/examples/threaded-ssl.c b/docs/examples/threaded-ssl.c new file mode 100644 index 000000000..e49443d40 --- /dev/null +++ b/docs/examples/threaded-ssl.c @@ -0,0 +1,124 @@ +/***************************************************************************** + * _ _ ____ _ + * 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