From cascardo at minaslivre.org Wed Jun 8 17:16:41 2005 From: cascardo at minaslivre.org (cascardo at minaslivre.org) Date: Wed, 8 Jun 2005 12:16:41 -0300 Subject: [Help-gnutls] Asynchronous application and not enough buffer ready Message-ID: <20050608151641.GC2254@cascardo.localdomain> 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. -- -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature URL: From nmav at gnutls.org Wed Jun 8 20:33:03 2005 From: nmav at gnutls.org (Nikos Mavrogiannopoulos) Date: Wed, 8 Jun 2005 20:33:03 +0200 Subject: [Help-gnutls] Asynchronous application and not enough buffer ready In-Reply-To: <20050608151641.GC2254@cascardo.localdomain> References: <20050608151641.GC2254@cascardo.localdomain> Message-ID: <200506082033.04302.nmav@gnutls.org> 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 From cascardo at minaslivre.org Wed Jun 8 20:46:08 2005 From: cascardo at minaslivre.org (cascardo at minaslivre.org) Date: Wed, 8 Jun 2005 15:46:08 -0300 Subject: [Help-gnutls] Asynchronous application and not enough buffer ready In-Reply-To: <200506082015.58605.n.mavrogiannopoulos@student.tue.nl> References: <20050608151641.GC2254@cascardo.localdomain> <200506082015.58605.n.mavrogiannopoulos@student.tue.nl> Message-ID: <20050608184608.GA2265@cascardo.localdomain> 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 > > received. > This is correct. gnutls cannot decrypt until a full packet has been received. > -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature URL: From nmav at gnutls.org Wed Jun 8 21:27:16 2005 From: nmav at gnutls.org (Nikos Mavrogiannopoulos) Date: Wed, 8 Jun 2005 21:27:16 +0200 Subject: [Help-gnutls] Asynchronous application and not enough buffer ready In-Reply-To: <20050608184608.GA2265@cascardo.localdomain> References: <20050608151641.GC2254@cascardo.localdomain> <200506082015.58605.n.mavrogiannopoulos@student.tue.nl> <20050608184608.GA2265@cascardo.localdomain> Message-ID: <200506082127.16313.nmav@gnutls.org> 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 From cascardo at minaslivre.org Wed Jun 8 21:44:27 2005 From: cascardo at minaslivre.org (cascardo at minaslivre.org) Date: Wed, 8 Jun 2005 16:44:27 -0300 Subject: [Help-gnutls] Asynchronous application and not enough buffer ready In-Reply-To: <20050608184608.GA2265@cascardo.localdomain> References: <20050608151641.GC2254@cascardo.localdomain> <200506082015.58605.n.mavrogiannopoulos@student.tue.nl> <20050608184608.GA2265@cascardo.localdomain> Message-ID: <20050608194427.GD2265@cascardo.localdomain> 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. -- -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature URL: