cURL / Mailing Lists / curl-library / Single Mail


CURL POST operation using read and write threads

From: Senthil Raja Velu <>
Date: Fri, 30 Jan 2009 19:02:23 -0800

I am newbie to curl and trying to figure out how to use it with multi
threads. I need to perform a POST operation with XML content using a
multi threaded program. I need to perform the request operation in one
thread and read the response in another thread. I see the
curl_easy_perform does it all on one operation. But how do we make the
write operation in one thread and read operation in another. Any help is
greatly appreciated.

Here is the sample code snippet that I need to dissect between write and
read threads;

    curl = curl_easy_init();

    if(curl) {
        curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
        curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &my_debug);
        curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);

        curl_easy_setopt(curl, CURLOPT_URL, "");
        curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
                curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
                curl_easy_setopt(curl, CURLOPT_ERRORBUFFER,_errBuf);
                curl_easy_setopt(curl, CURLOPT_HEADER, 1L);

        res = curl_easy_perform(curl);

        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
        curl_easy_setopt(curl, CURLOPT_FILE,(void *)&memStruct);
        curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION,
        curl_easy_setopt(curl, CURLOPT_WRITEHEADER,(void *)&httpHeader);

        _headerList = curl_slist_append(_headerList, "Content-Type:
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, _headerList);

        curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, requestLen);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request);
        curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 0L);

        if((retVal = curl_easy_perform(curl)) != 0)
            printf("POST(): Error ! - %s error:%d retVal:%d\n",

            return -2;

        printf("POST(): Received %d bytes\n", memStruct.size);
        printf("%s\n", memStruct.memory);


Received on 2009-01-31