cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: curl_easy_recv and disconnections

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Wed, 16 Jan 2013 15:46:03 +0100 (CET)

On Sun, 13 Jan 2013, Craig Davison wrote:

> When using curl_easy_recv(), what is the correct way to determine if the
> peer has disconnected?

That's a good question. I would've said that it would return 0 bytes read, but
you say it doesn't...

> When using the socket API, recv() will return a length of 0 when the peer
> has disconnected. In my own testing, it looks like curl_easy_recv() will
> return CURLE_UNSUPPORTED_PROTOCOL (1) in this case, but that does not seem
> to be documented anywhere. Is that the correct error code to look for?

That seems completely inappropriate and if that is indeed what happens I think
we should work on fixing it!

> Also, rarely, curl_easy_recv() will return CURLE_OK, but set n=0. What does
> this mean? Does it also mean the peer has disconnected?

Well, we need a way to differentiate EWOULDLBOCK from a closed connection, but
other than that I would say that 0 would imply disconnect but I haven't
actually studied the code right now, nor done any particular experiments...

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