cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: HTTPS and Multi-threading

From: Olano, Ever <eolano_at_cybersource.com>
Date: Wed, 30 Jun 2004 11:24:07 -0700

Hello, Dirk. Sorry to bring this up again. In the OpenSSL
documentation, it says of id_function():

id_function(void) is a function that returns a thread ID. It is not
needed on Windows nor on platforms where getpid() returns a different ID
for each thread (most notably Linux).

How come in your code below you had to set an id callback when you were
targeting Linux (for which, according to the doc, it's not needed)?
Didn't it work without one? Or you thought it wouldn't hurt? Does it
work fine for you?

Thanks,
Ever

------------------------------------------------------------------------

----
Message: 3
Date: Fri, 11 Jun 2004 14:22:38 +0200
From: Dirk Manske <dm_at_sysformance.com>
Subject: Re: HTTPS and Multi-threading
To: libcurl development <curl-library_at_cool.haxx.se>
Message-ID: <200406111422.39016.dm_at_sysformance.com>
Content-Type: text/plain;  charset="iso-8859-1"
On Wednesday 09 June 2004 03:14, Olano, Ever wrote:
> 2. > What's that [mttest.c]?
> It's the sample code in OpenSSL that shows how to implement and set
> the callback functions needed for multithreading to work.  I wanted to
know if
> anyone has tried it as I wanted to just copy it.  Do you or anyone, by
any
> chance, have their own code for the locking and id callback functions?
After a short look at mttest.c I wrote following code (for linux):
static pthread_mutex_t *ssl_mutexes = NULL;
static int ssl_mutexes_cnt = 0;
void sslLocking(int mode, int n, const char *file, int line) {
    if( n < ssl_mutexes_cnt ) {
        if( mode&CRYPTO_LOCK ) {
           pthread_mutex_lock( &(ssl_mutexes[n]) );
        } else if( mode&CRYPTO_UNLOCK ) {
           pthread_mutex_unlock( &(ssl_mutexes[n]) );
        }
        return;
    }
     // error...
}
unsigned long sslThreadId(void)
{
    return (unsigned long)pthread_self();
}
...
    // create ssl mutexes
    ssl_mutexes_cnt = CRYPTO_num_locks();
    ssl_mutexes = (pthread_mutex_t*) malloc( ssl_mutexes_cnt *
sizeof(pthread_mutex_t) );
    for( int i=0; i<ssl_mutexes_cnt; i++ ) {
        if( pthread_mutex_init( &(ssl_mutexes[i]), NULL ) != 0 ) {
            // error...
            abort();
        }
    }
    CRYPTO_set_locking_callback( sslLocking );
    CRYPTO_set_id_callback( sslThreadId );
....
    // free ssl mutexes
    if( ssl_mutexes ) {
        for( int i=0; i<ssl_mutexes_cnt; i++ ) {
            pthread_mutex_destroy( &(ssl_mutexes[i]) );
        }
        free( ssl_mutexes );
    }
Received on 2004-06-30