cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: DarwinSSL in infinite loop when server stops arbitrarily?

From: Aki Koskinen <curl_at_akikoskinen.info>
Date: Sun, 03 Mar 2013 12:13:38 +0200

On 03/02/2013 07:58 PM, Aki Koskinen wrote:
> The actual difference between SSLSample and curl - as far as I was able
> to pinpoint - is that when calling read() on the socket a failure
> happens (0 is returned). The real error at this point is in errno. For a
> reason that I don't know SSLSample receives ENOENT but curl receives
> EAGAIN. Hence, SSLSample notices that the other end of the socket is no
> more but curl just keeps on trying again and again.

 From 'man 2 read':

"RETURN VALUES
If successful, the number of bytes actually read is returned. Upon
reading end-of-file, zero is returned. Otherwise, a -1 is returned and
the global variable errno is set to indicate the error."

To me that says that if read() returns 0, errno isn't set to anything.
It's only set when -1 is returned. The code in curl_darwinssl.c (method
SocketRead) is however:

96: rrtn = read(sock, currData, bytesToGo);
97: if(rrtn <= 0) {
98: /* this is guesswork... */
99: theErr = errno;
100: if((rrtn == 0) && (theErr == 0)) {
101: /* try fix for iSync */
102: rtn = errSSLClosedGraceful;
103: }
104: else /* do the switch */
105: switch(theErr) {

On line 100 errno (which is now set to theErr) is examined even though
read() returned 0. I tried to remove the test after && on line 100 and
run my test again and curl didn't hang on that case.

Any ideas if I might have some truth in my guesswork here?

-- 
Aki Koskinen
http://www.akikoskinen.info/
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2013-03-03