curl-library
Re:curl-library Digest, Vol 128, Issue 35
Date: Thu, 28 Apr 2016 21:07:22 +0800 (CST)
Hi Daniel,
I just solved the problem. The problem is not with the data which is not SEND completely. The data is not RECEIVED completely. The is loop as below in the sample code. It would break directly if the result of curl_easy_recv is not CURLE_OK. But there is one situation that should NOT break. If the result is CURLE_AGAIN, it means there is still data to read in the socket and we should wait a moment and try again to recv data from the socket. After I modified the code as following, the sample worked fine in my test environment. Thank you for your help.
PS: Could we update the sample code in curl website to fix this bug? ^_^
for(;;)
{
char buf[1024+1];
memset (buf, 0, sizeof (buf));
iolen = 0;
wait_on_socket(sockfd, 1, 60000L);
res = curl_easy_recv(curl, buf, 1024, &iolen);
if(CURLE_OK != res)
{
if (CURLE_AGAIN == res)
{
printf ("CURLE_AGAIN returned! Try to read again!");
continue;
}
printf ("res is [%d][%s]\n", res, curl_easy_strerror(res));
break;
}
nread = (curl_off_t)iolen;
printf("Received %" CURL_FORMAT_CURL_OFF_T " bytes.\n", nread);
printf ("%s", buf);
}
>>
>>Message: 3
>>Date: Thu, 28 Apr 2016 10:02:17 +0200 (CEST)
>>From: Daniel Stenberg <daniel_at_haxx.se>
>>To: libcurl development <curl-library_at_cool.haxx.se>
>>Subject: Re: Problem found testing the sample code
>>Message-ID: <alpine.DEB.2.20.1604280958570.5747_at_tvnag.unkk.fr>
>>Content-Type: text/plain; charset=US-ASCII; format=flowed
>>
>>On Wed, 27 Apr 2016, lyx wrote:
>>
>>> I'm testing libcurl sample code in my ubuntu. This code is as listed in
>>> https://curl.haxx.se/libcurl/c/sendrecv.html. I copied it from above webpage
>>> and compiled in my ubuntu. I enabled VERBOS option and changed the URL to
>>> https://www.baidu.com to test customized send and recv under https protocol.
>>> I find the sample code worked sometimes I run it while failed to work in
>>> other times.
>>
>>Then please give us more details (what the problems are, which libcurl version
>>you're using on what platform and what TLS backend you use). I tried it now
>>against my own HTTPS site and it seemed to behave fine many times in a row.
>>
>>> The sample code will not display any https reply or can only
>>> display part of the reply.
>>
>>The sample code doesn't display any request nor response, correct. That's by
>>design. It's only a small (and silly) example.
>>
>>> If I only use curl_easy_perform to test this website without using recv and
>>> send function, it worked every time.
>>
>>You should also be aware that we *strongly* discourage the use of
>>curl_easy_recv and curl_easy_send if you intend to use one of the protocols
>>libcurl already supports.
>>
>>--
>>
>> / daniel.haxx.se
>>
>>
>>------------------------------
>>
>>Subject: Digest Footer
>>
>>_______________________________________________
>>curl-library mailing list
>>curl-library_at_cool.haxx.se
>>http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-library
>>
>>
>>------------------------------
>>
>>End of curl-library Digest, Vol 128, Issue 34
>>*********************************************
>-------------- next part --------------
>An HTML attachment was scrubbed...
>URL: <http://cool.haxx.se/pipermail/curl-library/attachments/20160428/3fe2770d/attachment-0001.html>
>
>------------------------------
>
>Message: 2
>Date: Thu, 28 Apr 2016 14:02:08 +0200 (CEST)
>From: Daniel Stenberg <daniel_at_haxx.se>
>To: libcurl development <curl-library_at_cool.haxx.se>
>Subject: Re: Problem found testing the sample code
>Message-ID: <alpine.DEB.2.20.1604281359510.5747_at_tvnag.unkk.fr>
>Content-Type: text/plain; charset=US-ASCII; format=flowed
>
>On Thu, 28 Apr 2016, lyx wrote:
>
>> /* Send the request. Real applications should check the iolen
>> * to see if all the request has been sent */
>
>I think you need to read this comment above an extra time.
>
>> res = curl_easy_send(curl, request, strlen(request), &iolen);
>
>See, there's no checking 'iolen' here. How much of the request was sent?
>
>--
>
> / daniel.haxx.se
>
>
>------------------------------
>
>Subject: Digest Footer
>
>_______________________________________________
>curl-library mailing list
>curl-library_at_cool.haxx.se
>http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-library
>
>
>------------------------------
>
>End of curl-library Digest, Vol 128, Issue 35
>*********************************************
-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-04-28