cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: easy API: curl_easy_perform() doesn't return after receiving all data

From: James Buchanan <software.au_at_gmail.com>
Date: Mon, 6 Nov 2006 18:09:21 +1100

On 11/4/06, Daniel Stenberg <daniel_at_haxx.se> wrote:
> On Sat, 4 Nov 2006, James Buchanan wrote:
>
> > I think what's happening is this: CURL tries to send data to the DNS peer, I
> > saw it when allowing it to get through my firewall, but it "failed sending
> > data to the peer" and got what it needed with either the Windows DNS service
> > or on Linux with some other method, but succeeds in sending to port 80. Does
> > that sound right?
>
> Not really, since libcurl first resolves the name and only after that it
> connects to the remote site. So if the name resolve fails, it never tries to
> access anything else.
>
> CURLE_SEND_ERROR is however a return code you get when libcurl has failed to
> send data over the network to the remote server (and this doesn't include DNS
> traffic which is done separately).

Thank you very much for that. It's now starting to make sense. I know
that the Google SOAP Search API often goes offline and gives spurious
errors like "Bad Gateway" and so on. It seems to me that either
Google's server is buggy and causes libcurl to give an incorrect
CURLE_SEND_ERROR (I use curl_easy_getinfo for the HTTP response code
and it's 200), or there's another problem with curl somewhere. As you
say it never tries again without being told, so it is guaranteed that
if I make only one call to curl_easy_perform() it only POSTs my data
to the server exactly once for each curl_easy_perform, right?

Attached is a little test program and the output it gives. Am I doing
something wrong?

Should I do something like this as a work-around?

CURLcode rc = curl_easy_perform(hCurl);

if (rc != CURLE_OK) {
   long int stats;
   CURLcode hc = curl_easy_getinfo(hCurl, CURLINFO_HTTP_CODE, &stats);
   if (stats == 200) {
      // Everything's actually OK, rc should have been CURLE_OK
   }
   else {
      // We really did have an error
   }
}

Sample run of attached test program:

james_at_spartacus:~/curl_test$ g++ -Wall -O2 -g -o testcurl testcurl.cpp
`curl-config --libs`

james_at_spartacus:~/curl_test$ ./testcurl
Enter google query: foobar
CURL info: About to connect() to api.google.com port 80 (#0)

CURL info: Trying 216.239.37.104...
CURL info: connected

CURL info: Connected to api.google.com (216.239.37.104) port 80 (#0)

CURL HTTP Header Out: POST /search/beta2 HTTP/1.1
Host: api.google.com
Accept: */*
Content-Type: text/xml; charset=utf-8
Content-Length: 829
SOAPAction: urn:GoogleSearchAction

CURL HTTP Header In: HTTP/1.1 200 OK

CURL HTTP Header In: Content-Type: text/xml; charset=utf-8

CURL HTTP Header In: Cache-control: private

CURL HTTP Header In: Transfer-Encoding: chunked

CURL HTTP Header In: Date: Mon, 06 Nov 2006 07:00:50 GMT

CURL HTTP Header In: Server: GFE/1.3

CURL info: select/poll returned error

CURL info: failed sending data to the peer

Error from CURL: failed sending data to the peer
HTTP response code: 200
Want to see the data returned by Google? n
CURL info: Closing connection #0

Received on 2006-11-06