gnutls_record_recv() hangs

Michael Cronenworth mike at
Mon Aug 15 23:54:49 CEST 2011

Dinh Le wrote:
> But this hack does not work since the previously received message may
> be less than 1024 bytes long but there are still more data available
> for receiving.  Worse yet, gnutls_record_recv() would hang indefinitely
> if there's no data available to be received.

You will need to use non-blocking I/O if you want to do multiple reads 
without hanging.

You have two options:
1. Add large static buffers and do one read.
2. Use non-blocking I/O and do multiple reads in blocks (the size can be 
up to you) and dynamically allocate memory to receive an unknown size 
data packet.

More information about the Gnutls-help mailing list