cURL / Mailing Lists / curl-library / Single Mail


Re: curl_easy_recv and disconnections

From: Daniel Stenberg <>
Date: Sat, 19 Jan 2013 22:57:51 +0100 (CET)

On Fri, 18 Jan 2013, Craig Davison wrote:

> I had a look at the libcurl code. curl_easy_recv() calls easy_connection().
> easy_connection() calls Curl_getconnectinfo(). If Curl_getconnectinfo() sees
> that the server has shut down the connection, it returns CURL_SOCKET_BAD,
> and easy_connection() returns CURLE_UNSUPPORTED_PROTOCOL with the error
> message "Failed to get recent socket". curl_easy_recv() in turn returns the
> error code from easy_connection().

Ick. You're completely right and I bet I even wrote that code myself but have
just completely forgotten about that detail since. Thanks for digging it up,
I'm adding this detail to the man pages for curl_easy_send() and
curl_easy_recv() right now!

> CURLE_OK/n=0 seems to happen when my connection does not use SSL or a proxy,
> and the function curl_easy_recv() uses to read is Curl_recv_plain. In that
> case, the n=0 comes directly from recv().
> curl_easy_recv will return CURLE_AGAIN if reading would block. This is
> documented and working properly.
> So it seems that both CURLE_UNSUPPORTED_PROTOCOL and CURLE_OK/n=0 indicate
> the connection has been shut down. I think this needs to be mentioned in
> the documentation.

Indeed. I'm adding that too now. Will push in a short while.

> But (IMO) I think ideally curl_easy_recv should never return 0, and in any
> case return a new error code like CURLE_PEER_DISCONNECTED if the connection
> is closed. The same would go for curl_easy_send.

Probably, yes. But changing that now will introduce a _third_ way for
applications that want to work with existing libraries too! I think I then
prefer to simply document the existing behavior...

List admin:
Received on 2013-01-19