cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: libcurl failures at a multi-threading application

From: Yamin Zhou <yamin_at_mavenir.com>
Date: Mon, 5 Sep 2011 22:29:40 +0000

> Let me repeat: use the SSL library's mutex callbacks. It seems to me that
> you're not using them:
>
> http://curl.haxx.se/docs/faq.html#Is_libcurl_thread_safe
>
> Inspiration to the actual implementations can be found in this example:
>
> http://curl.haxx.se/libcurl/c/threaded-ssl.html

tried with SSL mutex callbacks ...

#include <pthread.h>
#include <openssl/crypto.h>
static pthread_mutex_t* __ssl_mutex = NULL;

static void __ssl_locking(int mode, int n, const char* file, int line)
{
    if (mode & CRYPTO_LOCK)
        pthread_mutex_lock(&__ssl_mutex[n]);
    else
        pthread_mutex_unlock(&__ssl_mutex[n]);
}

static unsigned long __ssl_threadid(void)
{
    return ((unsigned long)pthread_self());
}

void __ssl_mutex_init()
{
    __ssl_mutex = (pthread_mutex_t*)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));

    for (int i = 0; i < CRYPTO_num_locks(); i++)
    {
        pthread_mutex_init(&__ssl_mutex[i], NULL);
    }
    CRYPTO_set_id_callback(__ssl_threadid);
    CRYPTO_set_locking_callback(__ssl_locking);
}

and in init() ...

    curl_global_init(CURL_GLOBAL_ALL);

    __ssl_mutex_init();

but still see failures ...

<17:29:38.334 **ERR** HCM 13285:13435 0:0>[onTransferDone(HttpClientWorker.cpp:370)] transfer[2]: failed due to Failed sending data to the peer
<17:29:38.334 **ERR** HCM 13285:13436 0:0>[onTransferDone(HttpClientWorker.cpp:370)] transfer[3]: failed due to Failed sending data to the peer
<17:29:38.356 **ERR** HCM 13285:13437 0:0>[onTransferDone(HttpClientWorker.cpp:370)] transfer[4]: failed due to Failure when receiving data from the peer
<17:29:38.356 **ERR** HCM 13285:13435 0:0>[onTransferDone(HttpClientWorker.cpp:370)] transfer[9]: failed due to Couldn't connect to server
<17:29:38.368 **ERR** HCM 13285:13447 0:0>[onTransferDone(HttpClientWorker.cpp:370)] transfer[8]: failed due to Failure when receiving data from the peer
<17:29:38.368 **ERR** HCM 13285:13436 0:0>[onTransferDone(HttpClientWorker.cpp:370)] transfer[11]: failed due to Couldn't connect to server
<17:29:38.381 **ERR** HCM 13285:13435 0:0>[onTransferDone(HttpClientWorker.cpp:370)] transfer[16]: failed due to Couldn't connect to server
<17:29:38.384 **ERR** HCM 13285:13437 0:0>[onTransferDone(HttpClientWorker.cpp:370)] transfer[18]: failed due to Couldn't connect to server
<17:29:38.392 **ERR** HCM 13285:13440 0:0>[onTransferDone(HttpClientWorker.cpp:370)] transfer[7]: failed due to Failure when receiving data from the peer
<17:29:38.392 **ERR** HCM 13285:13439 0:0>[onTransferDone(HttpClientWorker.cpp:370)] transfer[20]: failed due to Couldn't connect to server
<17:29:38.449 *WRN* HCM 13285:13440 0:0>[onTransferDone(HttpClientWorker.cpp:362)] transfer[21]: response code 501
<17:29:38.477 **ERR** HCM 13285:13436 0:0>[onTransferDone(HttpClientWorker.cpp:370)] transfer[25]: failed due to Failure when receiving data from the peer
<17:29:38.477 **ERR** HCM 13285:13440 0:0>[onTransferDone(HttpClientWorker.cpp:370)] transfer[28]: failed due to Couldn't connect to server
<17:29:38.581 *WRN* HCM 13285:13436 0:0>[onTransferDone(HttpClientWorker.cpp:362)] transfer[32]: response code 414
<17:29:38.620 **ERR** HCM 13285:13440 0:0>[onTransferDone(HttpClientWorker.cpp:370)] transfer[43]: failed due to Failure when receiving data from the peer
<17:29:38.656 **ERR** HCM 13285:13436 0:0>[onTransferDone(HttpClientWorker.cpp:370)] transfer[46]: failed due to Failure when receiving data from the peer
<17:29:41.329 **ERR** HCM 13285:13436 0:0>[onTransferDone(HttpClientWorker.cpp:370)] transfer[146]: failed due to Failure when receiving data from the peer
<17:29:41.563 **ERR** HCM 13285:13440 0:0>[onTransferDone(HttpClientWorker.cpp:370)] transfer[158]: failed due to Server returned nothing (no headers, no data)
<17:29:43.376 **ERR** HCM 13285:13440 0:0>[onTransferDone(HttpClientWorker.cpp:370)] transfer[15]: failed due to Timeout was reached
<17:29:43.580 **ERR** HCM 13285:13436 0:0>[onTransferDone(HttpClientWorker.cpp:370)] transfer[39]: failed due to Couldn't connect to server
<17:29:46.556 **ERR** HCM 13285:13440 0:0>[onTransferDone(HttpClientWorker.cpp:370)] transfer[165]: failed due to Timeout was reached

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-09-06