cURL / Mailing Lists / curl-library / Single Mail

curl-library

share interface

From: Michael Mastroianni <MMastroianni_at_choicestream.com>
Date: Mon, 23 May 2005 14:11:26 -0400

I seem to be doing something incorrectly:

Here's more or less what I'm doing

    Lockable dnsLockable;

    void shareLock(CURL* handle,
                         curl_lock_data data,
                         curl_lock_access addess,
                         void * userptr)
    {
        Lockable *l = (Lockable *)(userptr);
        l->lock();
    }

    void shareUnlock(CURL* handle,
                           curl_lock_data data,
                           curl_lock_access addess,
                           void * userptr)
    {
        Lockable * l = (Lockable*)(userptr);
        l->unlock();
    }

//The Lockable class just wraps a mutex or critical section base on os

MultiCurlHandle::MultiCurlHandle(bool useAltDNS,
                                 const std::string & alt1,
                                 const std::string & alt2):
userAgent_(userAgentDefault_),
cookieFile_(cookieFileDefault_),
redirect_(redirectDefault_),
maxFollow_(maxFollowDefault_),
active_(false),
timeout_(timeoutDefault_),
useAlternateDNS_(useAltDNS),
alternateDNS1_(alt1),
alternateDNS2_(alt2)
{
    MultiCurlHandleInitializer::initialize();
    share_ = curl_share_init();
    curl_share_setopt(share_, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS);
    curl_share_setopt(share_, CURLSHOPT_LOCKFUNC, shareLock);
    curl_share_setopt(share_, CURLSHOPT_UNLOCKFUNC, shareUnlock);
    curl_share_setopt(share_, CURLSHOPT_USERDATA, &dnsLockable);
}

// Later on, I do
bool MultiCurlHandle::initHandle(RefCurlResponse r)
{
    int aresCode;
    CURLcode res;
    res = curl_easy_init_e(&(r->handle_), &aresCode);

    if (res)
    {
        CSM_LOG_ERROR(logger(),
                      "MultiCurlHandle::init failed, reason: " <<
curl_easy_strerror(res) << ".");
        if(aresCode != ARES_SUCCESS)
        {
            CSM_LOG_ERROR(logger(),
                          "MultiCurlHandle::init failed in ares, reason:
" << ares_strerror(aresCode) << ".");
        }
        return false;
    }
    handles_.push_back(r->handle_);
    curl_easy_setopt(r->handle_, CURLOPT_NOSIGNAL, 1);
    curl_easy_setopt(r->handle_, CURLOPT_USERAGENT, userAgent_.c_str());
    curl_easy_setopt(r->handle_, CURLOPT_TIMEOUT, timeout_);
    curl_easy_setopt(r->handle_, CURLOPT_NOPROGRESS, 1);
    curl_easy_setopt(r->handle_, CURLOPT_WRITEFUNCTION,
WriteMemoryCallbackStdString);
    //curl_easy_setopt(r->handle_, CURLOPT_COOKIEJAR,
cookieFile_.c_str());
    curl_easy_setopt(r->handle_, CURLOPT_FOLLOWLOCATION, redirect_);
    curl_easy_setopt(r->handle_, CURLOPT_MAXREDIRS, maxFollow_);
    curl_easy_setopt(r->handle_, CURLOPT_WRITEDATA, (void *)&(r->body));
    curl_easy_setopt(r->handle_, CURLOPT_URL, r->url_.c_str());
    curl_easy_setopt(r->handle_, CURLOPT_HEADERFUNCTION,
HeaderCallback);
    curl_easy_setopt(r->handle_, CURLOPT_HEADERDATA,
&(r->headerSet_));
    //curl_easy_setopt(r->handle_, CURLOPT_HEADERDATA, &r);
    curl_easy_setopt(r->handle_, CURLOPT_SHARE, share_);
    return true;
}

//the second time through, I get a seg fault in share.c
// on line 189 in my copy-- 7.12.3, I think
share->lockfunc(data, type, accesstype, share->clientdata);
This happens right after the second call to

curl_easy_setopt(r->handle_, CURLOPT_SHARE, share_);

I tried to step through, but it seems that the pointer to the fn is
bad--I'm guessing that I've done something wrong with my mutex fn.

Can anyone help with this?
Received on 2005-05-23