cascardo | 8 Jun 2005 17:16

Asynchronous application and not enough buffer ready

Hello,

First of all, thank for this wonderful software. I'm currently trying
to write some software using libgnet (that uses glib) and gnutls. The
version of gnutls I'm using is 1.0.16.

My application runs a glib loop, waiting for bytes in the TCP
connection. I put them on a buffer, and then calls
gnutls_record_recv. I have set the pull function to one that gets
bytes from that buffer.

When the record size is greater than what the application has already
put in the buffer, gnutls asks for bytes to the pull function which
have not yet been read from the socket. To read these bytes, the main
loop must run again. The pull function returns 0 bytes read twice
after pulling the bytes already read and record_recv returns with an
error indicating that a TLS packet of unexpected size has been
received.

Is there any way to solve this without changing the path bytes make
through my application? I have thought of a solution getting the bytes
from the socket in the pull function, but I'd like to keep this in the
main loop. Is that possible?

Regards,
Thadeu Cascardo.
--

(Continue reading)

Nikos Mavrogiannopoulos | 8 Jun 2005 20:33

Re: Asynchronous application and not enough buffer ready

On Wednesday 08 June 2005 17:16, cascardo <at> minaslivre.org wrote:
> Hello,

I'm not really sure I've understood the situation, but anyway my comments
are below.

> When the record size is greater than what the application has already
> put in the buffer, gnutls asks for bytes to the pull function which
> have not yet been read from the socket. To read these bytes, the main
> loop must run again. 
Then the pull function should return -1 and set errno to EAGAIN.

> The pull function returns 0 bytes read twice 
> after pulling the bytes already read and record_recv returns with an
> error indicating that a TLS packet of unexpected size has been
> received.
This is correct. gnutls cannot decrypt until a full packet has been received.

--

-- 
Nikos Mavrogiannopoulos
cascardo | 8 Jun 2005 20:46

Re: Asynchronous application and not enough buffer ready

Well, that was the kind of solution I was looking for. Something that
would not require reading from the socket outside the main loop.

However, the solution proposed has made gnutls_record_recv go into a
loop. It should return with 0 bytes read to the caller. I will check
out the code and see if it's possible. If not, I will have to use some
solutions I didn't want to.

Thanks for the reply.

Regards,
Thadeu Cascardo.
--

On Wed, Jun 08, 2005 at 08:15:58PM +0200, Nikos Mavrogiannopoulos wrote:
> On Wednesday 08 June 2005 17:16, cascardo <at> minaslivre.org wrote:
> > Hello,
> 
> I'm not really sure I've understood the situation, but anyway my comments
> are below.
> 
> > When the record size is greater than what the application has already
> > put in the buffer, gnutls asks for bytes to the pull function which
> > have not yet been read from the socket. To read these bytes, the main
> > loop must run again. 
> Then the pull function should return -1 and set errno to EAGAIN.
> 
> > The pull function returns 0 bytes read twice 
> > after pulling the bytes already read and record_recv returns with an
> > error indicating that a TLS packet of unexpected size has been
(Continue reading)

Nikos Mavrogiannopoulos | 8 Jun 2005 21:27

Re: Asynchronous application and not enough buffer ready

On Wednesday 08 June 2005 20:46, cascardo <at> minaslivre.org wrote:

> Well, that was the kind of solution I was looking for. Something that
> would not require reading from the socket outside the main loop.
> However, the solution proposed has made gnutls_record_recv go into a
> loop. It should return with 0 bytes read to the caller. I will check
0 means EOF from the stream so it is not a valid return value.
gnutls should return GNUTLS_E_AGAIN. It will not get in a loop.

--

-- 
Nikos Mavrogiannopoulos
cascardo | 8 Jun 2005 21:44

Re: Asynchronous application and not enough buffer ready

On Wed, Jun 08, 2005 at 03:46:08PM -0300, cascardo <at> minaslivre.org wrote:
> However, the solution proposed has made gnutls_record_recv go into a
> loop. It should return with 0 bytes read to the caller. I will check
> out the code and see if it's possible. If not, I will have to use some
> solutions I didn't want to.
> 
> On Wed, Jun 08, 2005 at 08:15:58PM +0200, Nikos Mavrogiannopoulos wrote:
> > On Wednesday 08 June 2005 17:16, cascardo <at> minaslivre.org wrote:
> > 
> > > When the record size is greater than what the application has already
> > > put in the buffer, gnutls asks for bytes to the pull function which
> > > have not yet been read from the socket. To read these bytes, the main
> > > loop must run again. 
> > Then the pull function should return -1 and set errno to EAGAIN.
> > 

In fact, the code really does return when the pull function returns
with EAGAIN errno. However, my pull function gets called before
gnutls_record_recv returns. I will try harder to debug it, although I
may have to build a non-stripped debugging version of gnutls.

Thanks,

Thadeu Cascardo.
--

_______________________________________________
Help-gnutls mailing list
(Continue reading)


Gmane