[gnutls-help] gnutls_record_send says it sent more than I told it to!?

Nikos Mavrogiannopoulos n.mavrogiannopoulos at gmail.com
Wed Feb 3 21:11:35 CET 2016


On Tue, 2016-02-02 at 19:02 +0100, Mathieu Chouquet-Stringer wrote:
> Hello Nikos,
> 
> On Tue, Feb 02, 2016 at 06:34:26PM +0100, Nikos Mavrogiannopoulos 
> wrote:
> > Could it be that you are resuming a previously interrupted send? If 
> > the
> > previous send was interrupted and returned GNUTLS_E_AGAIN or
> > GNUTLS_E_INTERRUPTED then it will be resumed on the next call, 
> > unless
> > you call gnutls_record_discard_queued().
> 
> Yes I guess the logic of my code is somewhat defective (TM).
> 
> My issue is the following: because I use non blocking sockets 
> (without
> threads), if gnutls_record_send ever returns GNUTLS_E_INTERRUPTED or
> GNUTLS_E_AGAIN, I can't busy loop until it works. If I do so, all 
> other
> sessions will be stuck. Plus it appears if I kill the socket while 
> I'm
> looping on gnutls_record_send, the loop will keep on being 
> executed...
> 
> Bottom line is I cannot do:
> 
> 	do {
> 		sent = gnutls_record_send(...);
> 	} while (sent == GNUTLS_E_INTERRUPTED || sent == 
> GNUTLS_E_AGAIN);
> 
> So what I do is I queue the write for later: I ask epoll to tell me 
> when
> I can actually write (EPOLLOUT) to the socket tied to that TLS 
> session.
> Is that what I'm supposed to do?

Yes. However, you must remember you had pending data already processed
for that send() and you do not need to specify them again.

> But before I get this event for that specific socket, I might have 
> done other things (aka been reading or writing from/to other TLS
> sessions).

Could it be that the data you intended to be send have been modified?

> So the question is as follow: does gnutls keep a private buffer per
> session (and direction, as in read buffer or write buffer) so when I
> call gnutls_record_send with data == NULL and size == 0, it does the
> right thing? Or can it get mixed up with other read/writes from
> different sessions?

Sessions are totally independent; they share no state except for the
credentials structures which are read-only.

regards,
Nikos






More information about the Gnutls-help mailing list