Re: nonblocking sockets (was: connect-timeouts)
Date: Mon, 7 Jan 2002 14:52:11 +0100 (MET)
On Fri, 4 Jan 2002, Georg Horn wrote:
> Hm, i made some experiments and it seems that openssl is not working
> with nonblocking sockets...
It works all right, it just behaves slightly different.
> This confirms my guess, that the signal just hits us during ssl-stuff.
> But when i comment out the line
> Curl_nonblock(sockfd, FALSE);
> in connect.c, so that the socket stays non-blocking, it doesn't work at all:
> > src/curl -v --connect-timeout 10 https://meine.db24.de
> doing dnslookup
> socket nonblocking
> waiting for connection
> connected, socket still non-blocking
> calling protocol-specific connect function
> doing Curl_SSLConnect
> Here it should display something like "* SSL connection using RC4-MD5"
> etc, but it doesn't, and later on reports an error:
No, because the connect is made non-blocking and it probably returned
something saying that it isn't quite connected yet. We need to add code in a
manner similar to the regular connect for the SSL connection too, when using
> * Connected to meine.db24.de (184.108.40.206)
> > GET / HTTP/1.1
> User-Agent: curl/7.9.2 (i686-pc-linux-gnu) libcurl 7.9.2 (OpenSSL 0.9.6)
> Host: meine.db24.de
> Pragma: no-cache
> Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
> curl: (23) SSL: error:00000000:lib(0):func(0):reason(0)
> * Closing connection #0
> So there is some more work to be done. Unfortunately, i have no idea
> how this ssl-stuff works, so i'll stay with the signal-solution for now...
I'll quote the SSL_connect() docs at
If the underlying BIO is non-blocking, SSL_connect() will also return when
the underlying BIO could not satisfy the needs of SSL_connect() to continue
the handshake. In this case a call to SSL_get_error() with the return value
of SSL_connect() will yield SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE.
The calling process then must repeat the call after taking appropriate
action to satisfy the needs of SSL_connect(). The action depends on the
underlying BIO. When using a non-blocking socket, nothing is to be done,
but select() can be used to check for the required condition. When using a
buffering BIO, like a BIO pair, data must be written into or retrieved out
of the BIO before being able to continue.
-- Daniel Stenberg -- curl groks URLs -- http://curl.haxx.se/Received on 2002-01-07