gnutls_record_check_pending() broken?

Simon Josefsson simon at josefsson.org
Thu May 28 20:28:34 CEST 2009


Peter Hendrickson <pdh at wiredyne.com> writes:

> Simon writes:
>> Simon Josefsson <simon at josefsson.org> writes:
>> > Peter Hendrickson <pdh at wiredyne.com> writes:
>> >
>> >> gnutls_record_check_pending() doesn't work for me.  It always returns
>> >> 0, even when data is pending.
>> >
>> > How did you test this?  A small code demonstrating the problem would
>> > help.  I'll see if I can get something to work too...
>> 
>> Indeed, the patch below against mini.c demonstrate it working.  For me
>> it prints:
>
> It prints for me, too.
>
> What happens if you put the record_check_pending() call before you do
> the gnutls_record_recv()?  For me, it reports no bytes pending, even
> if I do a sleep(10).

That won't work: the purpose of gnutls_record_check_pending() is to
check if there is data stored in buffers within GnuTLS.  Before you call
gnutls_record_recv, there won't be any data in the buffers.  After a
call to gnutls_record_recv, the data that was not returned to the caller
of the function will be stored in an internal buffer.  The purpose of
the function is to find out if there is such data pending.

So I don't see a problem here actually.  It sounds as if you should use
poll/select to check if there is data pending to be read from the
socket.  When that is true, you should call gnutls_record_recv.  Of that
returns a complete buffer, you can call gnutls_record_check_pending how
much data is stored in a buffer -- that amount of data can be read
without a blocking socket read, again by calling gnutls_record_recv.

/Simon





More information about the Gnutls-devel mailing list