Handling network disconnects during read

Nikos Mavrogiannopoulos nmav at gnutls.org
Sat Oct 10 10:01:24 CEST 2009

Michael Welsh Duggan wrote:
> I've been encountering a problem using gnutls_record_recv() using old
> versions of gnutls, and I want to find out if a) current versions are
> not subject to this problem, or b) there is a decent workaround to this
> problem that I have not considered.  The version of gnutls that I am
> currently constrained to work with is v1.4.1.
> I am reading data using gnutls_record_recv().  I am using select() to
> determine whether there is data available on that socket before calling
> gnutls_record_recv().  Internally, gnutls_record_recv() appears to be
> doing multiple recv calls until "enough" data is read.  If a network
> disconnect happens in between recv calls in such a way that the os
> cannot determine that the connection is disconnected, then the recv
> call blocks.  This currently hangs my software.

 Unfortunately this problem cannot be solved unless you use non blocking
sockets. The usage of select() with gnutls functions has this
side-effect since select only tells if there are data in the socket, not
if they are enough for a gnutls read.

> I have a potential workaround I am looking at involving writing my own
> pull function, but I am not particularly happy with it.  Any
> suggestions?

If you want to stick on blocking sockets this is the "correct" solution.


More information about the Gnutls-help mailing list