[gnutls-dev] SSL_connect and non-blocking i/o

Emile van Bergen emile-gnutls at e-advies.nl
Thu Jul 13 11:44:53 CEST 2006


Hi,

On Thu, Jul 13, 2006 at 12:53:00AM +0000, Jefferson Ogata wrote:

> In libextra/gnutls_openssl.c, we have:
> 
> int
> SSL_connect (SSL * ssl)
> {
> ...
>   err = gnutls_handshake (ssl->gnutls_state);
> 
> Meanwhile, the gnutls_handshake() docs indicate that gnutls_handshake()
> should be called repeatedly until err == 0 or gnutls_error_is_fatal(err)
> is true.
> 
> So I'm debugging an application that uses the gnutls/OpenSSL
> compatibility and is using a non-blocking socket for the underlying
> transport; it returns from SSL_connect() without completing a handshake.
> I tweak gnutls libextra/gnutls_openssl.c as follows and that fixes my
> problem:
> 
> -    err = gnutls_handshake(ssl->gnutls_state);
> +    do
> +    {
> +       err = gnutls_handshake(ssl->gnutls_state);
> +    } while (err < 0 && !gnutls_error_is_fatal (err));
> 
> I can't be the only person who has run into this, can I?

The idea is that you only repeat the call, but wait first till you
estimate it can now do a bit more, eg. because select has indicated data
has become available in the socket.

Simply adding a loop would seem to create a busy wait for data to
appear, and that can't be good.

Cheers,


Emile.

-- 
E-Advies - Emile van Bergen           emile at e-advies.nl      
tel. +31 (0)78 6136282           http://www.e-advies.nl    



More information about the Gnutls-dev mailing list