[glib-networking/mcatanzaro/#20] gnutls: fire source when buffered data is available to read



commit 45c9028487d18131950c08e952f019c8f8c57032
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Wed Jan 8 11:20:31 2020 -0600

    gnutls: fire source when buffered data is available to read
    
    Buffered data is readable data, so if applications that are polling to
    see whether data is readable, we need to check the GnuTLS buffer.
    
    Fixes #20

 tls/base/gtlsconnection-base.c     |  4 ++++
 tls/base/gtlsconnection-base.h     |  3 +++
 tls/gnutls/gtlsconnection-gnutls.c | 14 ++++++++++++++
 3 files changed, 21 insertions(+)
---
diff --git a/tls/base/gtlsconnection-base.c b/tls/base/gtlsconnection-base.c
index 93cfc8e..d851f99 100644
--- a/tls/base/gtlsconnection-base.c
+++ b/tls/base/gtlsconnection-base.c
@@ -911,6 +911,10 @@ g_tls_connection_base_check (GTlsConnectionBase  *tls,
       ((condition & G_IO_OUT) && priv->write_closing))
     return FALSE;
 
+  if (G_TLS_CONNECTION_BASE_GET_CLASS (tls)->check &&
+      G_TLS_CONNECTION_BASE_GET_CLASS (tls)->check (tls, condition))
+    return TRUE;
+
   /* Defer to the base stream or GDatagramBased. */
   return g_tls_connection_base_base_check (tls, condition);
 }
diff --git a/tls/base/gtlsconnection-base.h b/tls/base/gtlsconnection-base.h
index bacefab..81f5d1a 100644
--- a/tls/base/gtlsconnection-base.h
+++ b/tls/base/gtlsconnection-base.h
@@ -81,6 +81,9 @@ struct _GTlsConnectionBaseClass
 
   gboolean                    (*is_session_resumed)         (GTlsConnectionBase   *tls);
 
+  gboolean                    (*check)                      (GTlsConnectionBase   *tls,
+                                                             GIOCondition          direction);
+
   void                        (*push_io)                    (GTlsConnectionBase   *tls,
                                                              GIOCondition          direction,
                                                              gint64                timeout,
diff --git a/tls/gnutls/gtlsconnection-gnutls.c b/tls/gnutls/gtlsconnection-gnutls.c
index 39cc7c5..d944425 100644
--- a/tls/gnutls/gtlsconnection-gnutls.c
+++ b/tls/gnutls/gtlsconnection-gnutls.c
@@ -925,6 +925,19 @@ g_tls_connection_gnutls_is_session_resumed (GTlsConnectionBase *tls)
   return gnutls_session_is_resumed (priv->session);
 }
 
+static gboolean
+g_tls_connection_gnutls_check (GTlsConnectionBase *tls,
+                               GIOCondition        direction)
+{
+  GTlsConnectionGnutls *gnutls = G_TLS_CONNECTION_GNUTLS (tls);
+  GTlsConnectionGnutlsPrivate *priv = g_tls_connection_gnutls_get_instance_private (gnutls);
+
+  if (direction & G_IO_IN)
+    return !!gnutls_record_check_pending (priv->session);
+
+  return FALSE;
+}
+
 static GTlsConnectionBaseStatus
 g_tls_connection_gnutls_read (GTlsConnectionBase  *tls,
                               void                *buffer,
@@ -1149,6 +1162,7 @@ g_tls_connection_gnutls_class_init (GTlsConnectionGnutlsClass *klass)
   base_class->retrieve_peer_certificate                  = g_tls_connection_gnutls_retrieve_peer_certificate;
   base_class->complete_handshake                         = g_tls_connection_gnutls_complete_handshake;
   base_class->is_session_resumed                         = g_tls_connection_gnutls_is_session_resumed;
+  base_class->check                                      = g_tls_connection_gnutls_check;
   base_class->read_fn                                    = g_tls_connection_gnutls_read;
   base_class->read_message_fn                            = g_tls_connection_gnutls_read_message;
   base_class->write_fn                                   = g_tls_connection_gnutls_write;


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