cURL / Mailing Lists / curl-library / Single Mail

curl-library

Serverside disconnection vs. simple Closing connection #n

From: Istvan Hoffmann <hofione_at_gmail.com>
Date: Wed, 22 Apr 2009 09:42:54 +0200

Hi All,
    Iım trying to use curl easy to http_get a web camera stream. Everything
works perfectly except one thing.
If the server in the camera closes the connection curl only logs ³Closing
connection #n² and finishes the transfer from curl_easy_perform with error
code CURLE_OK :-O
This makes impossible to detect server side interruption.
(technically now we could treat every return from curl_easy_perform as a
server side disconnection, but in other cases the problem is a real thing)
I compiled a debug version of libcurl (7.19.3) and found in readwrite_data
function in transfer.c this code

At line 422:

if(0 >= nread) {
      /* if we receive 0 or less here, the server closed the connection
     and we bail out from this! */
      DEBUGF(infof(data, "nread <= 0, server closed connection,
bailing\n"));
      k->keepon &= ~KEEP_READ;
      break;
    }

This shows that curl breaks the read loop without setting returning result
value and returns simply CURLE_OK at the end of the function if server side
disconnect happened.

I'm really wondering is there any special reason why that function not set
result error to something like CURLE_GOT_NOTHING or CURL_PEER_DISCONNECTED
(which is totally not existing in the error code defined list, I know) to
let inform the caller the real reason of closing the connection.

I'm also interesting it if I would modify the code mentioned above to return
with an error result, would it case any problem in any cases later.

Thank you in advance.
Bests
Hofi
Received on 2009-04-22