Skip to content

curl_easy_perform stuck using ssl #401

@GoogleCodeExporter

Description

@GoogleCodeExporter
What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?
Curl easy perform just hangs. Is this something related to curl or mongoose. 
Looking at problems from both the sides. Is there any way to debug this problem 
and find out what is the reason ??


What version of the product are you using? On what operating system?
RHEL Linux 5.8


Please provide any additional information below.


I am using curl with openssl to put some data onto the mongoose server. The 
whole process of the sending the data is performed in a thread.

The problem is curl just hangs after getting the first block of data, which is 
retrieved using the call back fileSendHandler.  It sends the first block of 
data and it never comes back to the fileSendHandler again. Even if we have no 
data to send we need to at least return 0 to confirm the file transfer has been 
completed as per the curl documentation. In the mean time the mongoose server 
keeps on waiting for the data or close connection request which also never 
happens. The curl just doesn't come out of the curl_easy_perform. But curl 
outputs that the file transfer is complete.

    > * connected
    > * Connected to localhost (127.0.0.1) port 9091 (#0)
    > * successfully set certificate verify locations:
    > *   CAfile: /etc/pki/tls/certs/ca-bundle.crt   CApath: none
    > * SSL connection using AES256-GCM-SHA384
    > * Server certificate:
    > *        subject: C=US; ST=Texas; L=Houston; O=xxxxxx xxxxxx; OU=ESSN; CN=xx xxxx xxxxxx Manager; emailAddress=support@xx.com
    > *        start date: 2011-08-10 17:32:16 GMT
    > *        expire date: 2016-08-08 17:32:16 GMT
    > *        issuer: C=US; ST=Texas; L=Houston; O=xxxxxxxxxx; OU=ESSN; CN=xx xxxx xxxx xxxxx; emailAddress=support@xx.com
    > *        SSL certificate verify result: self signed certificate (18), continuing anyway.
    > > PUT /0 HTTP/1.1 User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) Host: localhost:9091 Accept: */* Content-Length:
    > 12121
    > 
    > Sent num 12121 bytes 
    > * We are completely uploaded and fine


spaces

    struct dataSet
    {
        QFile* file;
        bool data;
        QByteArray rawdata;
        size_t sent;
        size_t totalSize;
        int numblocks;

    }

    size_t CThreadClass::
    fileSendHandler(void *ptr, size_t size, size_t nmemb, void *data)
    {
        size_t tosend = size * nmemb;
        dataSet *temp  = (dataSet*)data;
        char* dptr = temp->rawdata.data();


        if((temp->sent+tosend) > temp->totalSize)
            tosend = temp->totalSize - temp->sent;

        if(tosend == 0)
            return 0;

        dptr += temp->sent;
        memcpy(ptr,dptr,tosend);
        temp->sent += tosend;
        temp->numblocks++;
        qDebug()<<"Sent num"<< temp->sent <<"bytes";
        return tosend;
    }

    sendData()
    {
        CURL* curl = curl_easy_init();

            m_dataset = new dataSet();
            m_dataset->data = true;
            m_dataset->sent = m_dataset->numblocks = 0;
            m_dataset->file = NULL;
            m_dataset->rawdata = all.toAscii(); //Qt code
            m_dataset->totalSize = all.toAscii().length(); //Qt code

            curl_easy_setopt(curl, CURLOPT_URL, m_uri.toAscii().data());
            curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L) ;
            curl_easy_setopt(curl, CURLOPT_PUT, 1L);
            curl_easy_setopt(curl, CURLOPT_INFILESIZE, all.toAscii().length());
            curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
            struct curl_slist *hlist = NULL;

            hlist = curl_slist_append(hlist, "Expect:");
            curl_easy_setopt(curl,CURLOPT_HTTPHEADER,hlist);
            curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
            curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, chunkSize);
            curl_easy_setopt(curl, URLOPT_VERBOSE, 1L);
            curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, NULL);
            curl_easy_setopt(curl, CURLOPT_HEADERDATA, NULL);
            curl_easy_setopt(curl, CURLOPT_READDATA, (void*)m_dataset);
            curl_easy_setopt(curl, CURLOPT_READFUNCTION, fileSendHandler);
            curl_easy_setopt(curl, CURLOPT_TRANSFERTEXT, 0L);
            curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
            if(isSSL) {
                 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
                 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
            }


            CURLcode errorCode =  curl_easy_perform(curl);
            /*if(m_File != NULL) {
                m_File->close();
                delete m_File;
                m_File = NULL;
            }*/

            if(m_dataset)
                delete m_dataset; 
    }


Original issue reported on code.google.com by bemineni...@gmail.com on 8 Aug 2013 at 6:18

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions