[gnutls-devel] Question regarding gnutls_record_set_timeout()

Nikos Mavrogiannopoulos nmav at gnutls.org
Thu Sep 17 14:53:06 CEST 2015


On Wed, Sep 16, 2015 at 4:57 PM, Tim Ruehsen <tim.ruehsen at gmx.de> wrote:
> Hi,
> I would like to use gnutls_record_set_timeout() instead of using my own
> timeout code.
> I see no way to specify an 'indefinite' timeout, e.g. by using a negative
> value. Should I set the fd to blocking or what is the best 'gnutls' way ?

The timeout for this function only makes sense with blocking fds. For
non-blocking fds you always have the function return as soon as
possible. By not setting a timeout with this function you get the
indefinite timeout. Does this answer your question?

> BTW, looking at the code in system_recv_timeout(), with high timeout values,
> there might be unexpected CPU usage due to this loop:
>
>         tv.tv_sec = 0;
>         tv.tv_usec = ms * 1000;
>
>         while (tv.tv_usec >= 1000000) {
>                 tv.tv_usec -=  1000000;
>                 tv.tv_sec++;
>         }
> IMHO, it could be replaced by
>         tv.tv_sec = ms / 1000;
>         tv.tv_usec = (ms % 1000) * 1000;

Indeed, this code was written with small timeout values in mind. I'll update it.

regards,
Nikos



More information about the Gnutls-devel mailing list