help-gsasl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/3] check whether gnutls session has buffered data


From: Enrico Scholz
Subject: [PATCH 2/3] check whether gnutls session has buffered data
Date: Sat, 12 Nov 2011 23:33:44 +0100

Code used a loop like

| while (...) {
|   poll([fd=<tls-fd>], ...);
|   ...
|   gnutls_record_recv(session, <buf>, <len>);

It is possible, that gnutls_record_recv() receives more data from
<tls-fd> than there can be copied to <buf> (e.g. when stream is
compressed).  In this case, the poll() in the next loop will block
because there is no data available from the socket, although a call from
gnutls_record_recv() would return the buffered payload.

Patch provides the infrastructure required by a later patch. It uses
gnutls_record_check_pending() to check whether there is buffered data.

Signed-off-by: Enrico Scholz <address@hidden>
---
 src/gsasl.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/gsasl.c b/src/gsasl.c
index 7dd2008..53dc116 100644
--- a/src/gsasl.c
+++ b/src/gsasl.c
@@ -832,6 +832,12 @@ main (int argc, char *argv[])
          char *sockbuf = NULL;
          /* we read chunks of 1000 bytes at a time */
          size_t sockpos = 0, sockalloc = 0, sockalloc1 = 1000;
+         bool pending_sock_data = false;
+
+#ifdef HAVE_LIBGNUTLS
+         if (using_tls)
+           pending_sock_data = gnutls_record_check_pending(session) > 0;
+#endif
 
          streaminput_open(&stdinstream, STDIN_FILENO);
 
@@ -946,8 +952,11 @@ main (int argc, char *argv[])
 
 #ifdef HAVE_LIBGNUTLS
                  if (using_tls)
-                   len = gnutls_record_recv (session, &sockbuf[sockpos],
-                                             sockalloc - sockpos);
+                   {
+                     len = gnutls_record_recv (session, &sockbuf[sockpos],
+                                               sockalloc - sockpos);
+                     pending_sock_data = gnutls_record_check_pending(session) 
> 0;
+                   }
                  else
 #endif
                    len = recv (sockfd, &sockbuf[sockpos],
-- 
1.7.7.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]