cURL / Mailing Lists / curl-library / Single Mail

curl-library

Problems with curl_easy_perform with call back function

From: Venkatesh Prabu Narayanan <venkateshprabu06_at_gmail.com>
Date: Fri, 24 May 2013 18:10:26 +0530

Hi,

I have some issues in using call back function which I would like to share
with you and get some ideas.

First let me explain the scenario,

From client side, I need to upload GBs of data (char buffer, not a actual
file, since I have to do some operations like compression on the fly) to
server. In the client side, I am using libcurl (version 7.19.3) to upload
data (not file) using call back function to remote server where in the data
was received from the socket and write into the file. Since I don't know
the actual size to be uploaded earlier, I couldn't set the exact
CURLOPT_INFILESIZE_LARGE. If I didn't set the above option, my call back
wasn't getting called and so I set this option to some large value say 50GB
using the curl_easy_setopt call. In the server side, a socket program is
running which is continuously streaming the data from the socket in which
we sent data from the libcurl in the client side.

The problem I faced here is, after sending the final block of data, I
return 0 to the call back function. But still curl_easy_perform() doesn't
return instead it is still hanging in this function and leaves the socket
connection open,

select() call in the function Curl_socket_ready().

While debugging the application, in server side, the application seems to
be wait in the 'SSL_Read()' function.

My understanding is that whenever I return zero in the call back function,
it should come out of call back function and in turn the
curl_easy_perform(). But that is not happening in my case. Is there any way
to close the current libcurl call after sending all the data ?

My sample code (slightly modified):

    double contLength = 50GB; //Just added GB here for easy reference.
    curl_easy_setopt(curlPtr, CURLOPT_READFUNCTION, ReadData);
    curl_easy_setopt(curlPtr, CURLOPT_READDATA, userpointer);
    curl_easy_setopt(curlPtr, CURLOPT_UPLOAD, 1L);
    curl_easy_setopt(curlPtr, CURLOPT_PUT, 1L);
    curl_easy_setopt(curlPtr, CURLOPT_WRITEFUNCTION, WriteResponseData);
    curl_easy_setopt(curlPtr, CURLOPT_WRITEDATA, userpointer);
    //curl_easy_setopt(curlPtr, CURLOPT_IGNORE_CONTENT_LENGTH, 1);
    curl_easy_setopt(curlPtr, CURLOPT_INFILESIZE_LARGE,
(curl_off_t)contLength);

size_t ReadData(void *ptr, size_t size, size_t nmemb, void* userp)
{
    MyClass* myObj = (MyClass*)userp;
    size_t bufSize = size * nmemb;
    size_t toRet = myObj->ReadDataFromMemory((
char*)ptr, bufSize);
    return toRet;
};

size_t WriteResponseData(void *ptr, size_t size, size_t nmemb, void* userp)
{
    MyClass* myObj = (MyClass*)userp;
    size_t bufSize = size * nmemb;
    size_t toRet = myObj->WriteDataToMemory((char*)ptr, bufSize);
    return toRet;
};

Please correct me if I am doing anything wrong here.

Regards,
Venkatesh

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-05-24