[glib-networking/mcatanzaro/#20: 2/6] Implement tls_source_sync() using check functions



commit 8ccd464f4eaa1ec08f0b568f4edeb75c31b529e8
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Sun Jan 26 14:26:38 2020 -0600

    Implement tls_source_sync() using check functions
    
    This is semantically elegant, and will help avoid code duplication.

 tls/base/gtlsconnection-base.c | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)
---
diff --git a/tls/base/gtlsconnection-base.c b/tls/base/gtlsconnection-base.c
index a4e5d43..b35cee4 100644
--- a/tls/base/gtlsconnection-base.c
+++ b/tls/base/gtlsconnection-base.c
@@ -944,30 +944,25 @@ tls_source_sync (GTlsConnectionBaseSource *tls_source)
 {
   GTlsConnectionBase *tls = tls_source->tls;
   GTlsConnectionBasePrivate *priv = g_tls_connection_base_get_instance_private (tls);
-  gboolean io_waiting, op_waiting;
+  gboolean check;
+  gboolean base_check;
+  gboolean io_waiting;
+  gboolean op_waiting;
 
   /* Was the source destroyed earlier in this main context iteration? */
   if (g_source_is_destroyed ((GSource *)tls_source))
     return;
 
-  g_mutex_lock (&priv->op_mutex);
-  if (((tls_source->condition & G_IO_IN) && priv->reading) ||
-      ((tls_source->condition & G_IO_OUT) && priv->writing) ||
-      (priv->handshaking && !priv->need_finish_handshake))
-    op_waiting = TRUE;
-  else
-    op_waiting = FALSE;
+  check = g_tls_connection_base_check (tls, tls_source->condition);
+  base_check = g_tls_connection_base_base_check (tls, tls_source->condition);
 
-  if (!op_waiting && !priv->need_handshake &&
-      !priv->need_finish_handshake)
-    io_waiting = TRUE;
-  else
-    io_waiting = FALSE;
-  g_mutex_unlock (&priv->op_mutex);
+  op_waiting = !check && base_check;
+  io_waiting = check && !base_check;
 
   if (op_waiting == tls_source->op_waiting &&
       io_waiting == tls_source->io_waiting)
     return;
+
   tls_source->op_waiting = op_waiting;
   tls_source->io_waiting = io_waiting;
 


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