[glib-networking/wip/tlssplit: 4/7] base: add abstraction for push_io and pop_io



commit 9e894a96b1c89c22972385f7d66e332611cde4d4
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Sun Aug 16 13:53:16 2015 +0200

    base: add abstraction for push_io and pop_io
    
    This is needed because we need to set the cancellable or whether
    the operation is blocking to the bio abstraction.

 tls/base/gtlsconnection-base.c |   55 +++++++++++++++++++++++++++++-----------
 tls/base/gtlsconnection-base.h |    9 ++++++
 2 files changed, 49 insertions(+), 15 deletions(-)
---
diff --git a/tls/base/gtlsconnection-base.c b/tls/base/gtlsconnection-base.c
index 0c922bf..1a6ce19 100644
--- a/tls/base/gtlsconnection-base.c
+++ b/tls/base/gtlsconnection-base.c
@@ -416,14 +416,12 @@ yield_op (GTlsConnectionBase       *tls,
   g_mutex_unlock (&tls->op_mutex);
 }
 
-void
-g_tls_connection_base_push_io (GTlsConnectionBase *tls,
-                              GIOCondition        direction,
-                              gboolean            blocking,
-                              GCancellable       *cancellable)
+static void
+g_tls_connection_base_real_push_io (GTlsConnectionBase *tls,
+                                    GIOCondition        direction,
+                                    gboolean            blocking,
+                                    GCancellable       *cancellable)
 {
-  g_assert (direction & (G_IO_IN | G_IO_OUT));
-
   if (direction & G_IO_IN)
     {
       tls->read_blocking = blocking;
@@ -439,16 +437,26 @@ g_tls_connection_base_push_io (GTlsConnectionBase *tls,
     }
 }
 
-GTlsConnectionBaseStatus
-g_tls_connection_base_pop_io (GTlsConnectionBase  *tls,
-                             GIOCondition         direction,
-                             gboolean             success,
-                             GError             **error)
+void
+g_tls_connection_base_push_io (GTlsConnectionBase *tls,
+                               GIOCondition        direction,
+                               gboolean            blocking,
+                               GCancellable       *cancellable)
 {
-  GError *my_error = NULL;
-
   g_assert (direction & (G_IO_IN | G_IO_OUT));
-  g_assert (!error || !*error);
+  g_return_if_fail (G_IS_TLS_CONNECTION_BASE (tls));
+
+  G_TLS_CONNECTION_BASE_GET_CLASS (tls)->push_io (tls, direction,
+                                                  blocking, cancellable);
+}
+
+static GTlsConnectionBaseStatus
+g_tls_connection_base_real_pop_io (GTlsConnectionBase  *tls,
+                                   GIOCondition         direction,
+                                   gboolean             success,
+                                   GError             **error)
+{
+  GError *my_error = NULL;
 
   if (direction & G_IO_IN)
     {
@@ -492,6 +500,20 @@ g_tls_connection_base_pop_io (GTlsConnectionBase  *tls,
   return G_TLS_CONNECTION_BASE_ERROR;
 }
 
+GTlsConnectionBaseStatus
+g_tls_connection_base_pop_io (GTlsConnectionBase  *tls,
+                              GIOCondition         direction,
+                              gboolean             success,
+                              GError             **error)
+{
+  g_assert (direction & (G_IO_IN | G_IO_OUT));
+  g_assert (!error || !*error);
+  g_return_val_if_fail (G_IS_TLS_CONNECTION_BASE (tls), G_TLS_CONNECTION_BASE_ERROR);
+
+  return G_TLS_CONNECTION_BASE_GET_CLASS (tls)->pop_io (tls, direction,
+                                                        success, error);
+}
+
 gboolean
 g_tls_connection_base_check (GTlsConnectionBase  *tls,
                             GIOCondition         condition)
@@ -1212,6 +1234,9 @@ g_tls_connection_base_class_init (GTlsConnectionBaseClass *klass)
   iostream_class->close_async       = g_tls_connection_base_close_async;
   iostream_class->close_finish      = g_tls_connection_base_close_finish;
 
+  klass->push_io = g_tls_connection_base_real_push_io;
+  klass->pop_io = g_tls_connection_base_real_pop_io;
+
   g_object_class_override_property (gobject_class, PROP_BASE_IO_STREAM, "base-io-stream");
   g_object_class_override_property (gobject_class, PROP_REQUIRE_CLOSE_NOTIFY, "require-close-notify");
   g_object_class_override_property (gobject_class, PROP_REHANDSHAKE_MODE, "rehandshake-mode");
diff --git a/tls/base/gtlsconnection-base.h b/tls/base/gtlsconnection-base.h
index 7cc1137..7f676bf 100644
--- a/tls/base/gtlsconnection-base.h
+++ b/tls/base/gtlsconnection-base.h
@@ -53,6 +53,15 @@ struct _GTlsConnectionBaseClass
   GTlsConnectionBaseStatus (*complete_handshake)   (GTlsConnectionBase  *tls,
                                                    GError             **error);
 
+  void                     (*push_io)              (GTlsConnectionBase  *tls,
+                                                    GIOCondition         direction,
+                                                    gboolean             blocking,
+                                                    GCancellable        *cancellable);
+  GTlsConnectionBaseStatus (*pop_io)               (GTlsConnectionBase  *tls,
+                                                    GIOCondition         direction,
+                                                    gboolean             success,
+                                                    GError             **error);
+
   GTlsConnectionBaseStatus (*read_fn)              (GTlsConnectionBase  *tls,
                                                    void                *buffer,
                                                    gsize                count,


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