[glib-networking/mcatanzaro/base-rebase: 8/33] base, openssl: support per-operation timeouts



commit 05e9370537d4de499bfc3211a6e60f258fddb685
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Thu Apr 4 21:59:53 2019 -0500

    base, openssl: support per-operation timeouts
    
    Port 5a0b3776dc94bb0779e4e321fbc3ff70a3dd359f
    
    Note there is a FIXME here as OpenSSL is internally still the same as
    before, either blocking or not.

 tls/base/gtlsconnection-base.c             | 87 ++++++++++++++++++++----------
 tls/base/gtlsconnection-base.h             | 19 ++++---
 tls/base/gtlsinputstream-base.c            |  5 +-
 tls/base/gtlsoutputstream-base.c           | 13 ++---
 tls/openssl/gtlsclientconnection-openssl.c |  3 +-
 tls/openssl/gtlsconnection-openssl.c       | 34 +++++++-----
 tls/openssl/gtlsserverconnection-openssl.c |  3 +-
 7 files changed, 105 insertions(+), 59 deletions(-)
---
diff --git a/tls/base/gtlsconnection-base.c b/tls/base/gtlsconnection-base.c
index 46ff295..6bf0d8c 100644
--- a/tls/base/gtlsconnection-base.c
+++ b/tls/base/gtlsconnection-base.c
@@ -59,7 +59,7 @@ static void g_tls_connection_base_dtls_connection_iface_init (GDtlsConnectionInt
 static void g_tls_connection_base_datagram_based_iface_init  (GDatagramBasedInterface  *iface);
 
 static gboolean do_implicit_handshake (GTlsConnectionBase  *tls,
-                                       gboolean             blocking,
+                                       gint64               timeout,
                                        GCancellable        *cancellable,
                                        GError             **error);
 static gboolean finish_handshake (GTlsConnectionBase  *tls,
@@ -319,7 +319,7 @@ typedef enum {
 static gboolean
 claim_op (GTlsConnectionBase    *tls,
           GTlsConnectionBaseOp   op,
-          gboolean               blocking,
+          gint64                 timeout,
           GCancellable          *cancellable,
           GError               **error)
 {
@@ -361,7 +361,7 @@ claim_op (GTlsConnectionBase    *tls,
           tls->need_handshake && !tls->handshaking)
         {
           tls->handshaking = TRUE;
-          if (!do_implicit_handshake (tls, blocking, cancellable, error))
+          if (!do_implicit_handshake (tls, timeout, cancellable, error))
             {
               g_cancellable_reset (tls->waiting_for_op);
               g_mutex_unlock (&tls->op_mutex);
@@ -402,12 +402,14 @@ claim_op (GTlsConnectionBase    *tls,
     {
       GPollFD fds[2];
       int nfds;
+      gint64 start_time;
+      gint result;
 
       g_cancellable_reset (tls->waiting_for_op);
 
       g_mutex_unlock (&tls->op_mutex);
 
-      if (!blocking)
+      if (timeout == 0)
         {
           g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK,
                                _("Operation would block"));
@@ -420,11 +422,41 @@ claim_op (GTlsConnectionBase    *tls,
       else
         nfds = 1;
 
-      g_poll (fds, nfds, -1);
+      /* Convert from microseconds to milliseconds. */
+      if (timeout != -1)
+        timeout /= 1000;
+
+      /* Poll until cancellation or the timeout is reached. */
+      start_time = g_get_monotonic_time ();
+
+      while (!g_cancellable_is_cancelled (tls->waiting_for_op) &&
+             !g_cancellable_is_cancelled (cancellable))
+        {
+          result = g_poll (fds, nfds, timeout);
+
+          if (result == 0)
+            break;
+          if (result != -1 || errno != EINTR)
+            continue;
+
+          if (timeout != -1)
+            {
+              timeout -= (g_get_monotonic_time () - start_time) / 1000;
+              if (timeout < 0)
+                timeout = 0;
+            }
+        }
 
       if (nfds > 1)
         g_cancellable_release_fd (cancellable);
 
+      if (result == 0)
+        {
+          g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_TIMED_OUT,
+                               _("Socket I/O timed out"));
+          return FALSE;
+        }
+
       goto try_again;
     }
 
@@ -477,19 +509,19 @@ yield_op (GTlsConnectionBase       *tls,
 static void
 g_tls_connection_base_real_push_io (GTlsConnectionBase *tls,
                                     GIOCondition        direction,
-                                    gboolean            blocking,
+                                    gint64              timeout,
                                     GCancellable       *cancellable)
 {
   if (direction & G_IO_IN)
     {
-      tls->read_blocking = blocking;
+      tls->read_timeout = timeout;;
       tls->read_cancellable = cancellable;
       g_clear_error (&tls->read_error);
     }
 
   if (direction & G_IO_OUT)
     {
-      tls->write_blocking = blocking;
+      tls->write_timeout = timeout;
       tls->write_cancellable = cancellable;
       g_clear_error (&tls->write_error);
     }
@@ -498,14 +530,14 @@ g_tls_connection_base_real_push_io (GTlsConnectionBase *tls,
 void
 g_tls_connection_base_push_io (GTlsConnectionBase *tls,
                                GIOCondition        direction,
-                               gboolean            blocking,
+                               gint64              timeout,
                                GCancellable       *cancellable)
 {
   g_assert (direction & (G_IO_IN | G_IO_OUT));
   g_return_if_fail (G_IS_TLS_CONNECTION_BASE (tls));
 
   G_TLS_CONNECTION_BASE_GET_CLASS (tls)->push_io (tls, direction,
-                                                  blocking, cancellable);
+                                                  timeout, cancellable);
 }
 
 static GTlsConnectionBaseStatus
@@ -982,11 +1014,13 @@ handshake_thread (GTask        *task,
   GTlsConnectionBaseClass *tls_class = G_TLS_CONNECTION_BASE_GET_CLASS (tls);
   GError *error = NULL;
 
+  gint64 timeout = -1; /* FIXME: upcoming commit */
+
   tls->started_handshake = FALSE;
   tls->certificate_requested = FALSE;
 
   if (!claim_op (tls, G_TLS_CONNECTION_BASE_OP_HANDSHAKE,
-                 TRUE, cancellable, &error))
+                 timeout, cancellable, &error))
     {
       g_task_return_error (task, error);
       return;
@@ -998,7 +1032,7 @@ handshake_thread (GTask        *task,
     {
       GTlsConnectionBaseStatus status;
 
-      status = tls_class->request_rehandshake (tls, cancellable, &error);
+      status = tls_class->request_rehandshake (tls, timeout, cancellable, &error);
       if (status != G_TLS_CONNECTION_BASE_OK)
         {
           g_task_return_error (task, error);
@@ -1010,7 +1044,7 @@ handshake_thread (GTask        *task,
   tls->peer_certificate_errors = 0;
 
   tls->started_handshake = TRUE;
-  tls_class->handshake (tls, cancellable, &error);
+  tls_class->handshake (tls, timeout, cancellable, &error);
   tls->need_handshake = FALSE;
 
   if (error)
@@ -1227,7 +1261,7 @@ implicit_handshake_completed (GObject      *object,
 
 static gboolean
 do_implicit_handshake (GTlsConnectionBase  *tls,
-                       gboolean             blocking,
+                       gint64               timeout,
                        GCancellable        *cancellable,
                        GError             **error)
 {
@@ -1238,7 +1272,8 @@ do_implicit_handshake (GTlsConnectionBase  *tls,
                                         NULL);
   g_task_set_source_tag (tls->implicit_handshake, do_implicit_handshake);
 
-  if (blocking)
+  /* FIXME: Support (timeout > 0). */
+  if (timeout != 0)
     {
       GError *my_error = NULL;
       gboolean success;
@@ -1273,7 +1308,7 @@ gssize
 g_tls_connection_base_read (GTlsConnectionBase  *tls,
                             void                *buffer,
                             gsize                count,
-                            gboolean             blocking,
+                            gint64               timeout,
                             GCancellable        *cancellable,
                             GError             **error)
 {
@@ -1283,7 +1318,7 @@ g_tls_connection_base_read (GTlsConnectionBase  *tls,
   do
     {
       if (!claim_op (tls, G_TLS_CONNECTION_BASE_OP_READ,
-                     blocking, cancellable, error))
+                     timeout, cancellable, error))
         return -1;
 
       if (tls->app_data_buf && !tls->handshaking)
@@ -1299,7 +1334,7 @@ g_tls_connection_base_read (GTlsConnectionBase  *tls,
       else
         {
           status = G_TLS_CONNECTION_BASE_GET_CLASS (tls)->
-            read_fn (tls, buffer, count, blocking, &nread, cancellable, error);
+            read_fn (tls, buffer, count, timeout, &nread, cancellable, error);
         }
 
       yield_op (tls, G_TLS_CONNECTION_BASE_OP_READ, status);
@@ -1325,7 +1360,7 @@ g_tls_connection_base_read_message (GTlsConnectionBase  *tls,
 
   do {
     if (!claim_op (tls, G_TLS_CONNECTION_BASE_OP_READ,
-                   timeout != 0, cancellable, error))
+                   timeout, cancellable, error))
       return -1;
 
     /* Copy data out of the app data buffer first. */
@@ -1444,7 +1479,7 @@ gssize
 g_tls_connection_base_write (GTlsConnectionBase  *tls,
                              const void          *buffer,
                              gsize                count,
-                             gboolean             blocking,
+                             gint64               timeout,
                              GCancellable        *cancellable,
                              GError             **error)
 {
@@ -1454,11 +1489,11 @@ g_tls_connection_base_write (GTlsConnectionBase  *tls,
   do
     {
       if (!claim_op (tls, G_TLS_CONNECTION_BASE_OP_WRITE,
-                     blocking, cancellable, error))
+                     timeout, cancellable, error))
         return -1;
 
       status = G_TLS_CONNECTION_BASE_GET_CLASS (tls)->
-        write_fn (tls, buffer, count, blocking, &nwrote, cancellable, error);
+        write_fn (tls, buffer, count, timeout, &nwrote, cancellable, error);
 
       yield_op (tls, G_TLS_CONNECTION_BASE_OP_WRITE, status);
     }
@@ -1483,7 +1518,7 @@ g_tls_connection_base_write_message (GTlsConnectionBase  *tls,
 
   do {
     if (!claim_op (tls, G_TLS_CONNECTION_BASE_OP_WRITE,
-                   timeout != 0, cancellable, error))
+                   timeout, cancellable, error))
       return -1;
 
     status = G_TLS_CONNECTION_BASE_GET_CLASS (tls)->
@@ -1597,8 +1632,6 @@ g_tls_connection_base_close_internal (GIOStream      *stream,
    * this class and how the underlying stream is closed.
    */
 
-  /* FIXME: This does not properly support the @timeout parameter. */
-
   g_return_val_if_fail (direction != G_TLS_DIRECTION_NONE, FALSE);
 
   if (direction == G_TLS_DIRECTION_BOTH)
@@ -1608,14 +1641,14 @@ g_tls_connection_base_close_internal (GIOStream      *stream,
   else
     op = G_TLS_CONNECTION_BASE_OP_CLOSE_WRITE;
 
-  if (!claim_op (tls, op, TRUE, cancellable, error))
+  if (!claim_op (tls, op, timeout, cancellable, error))
     return FALSE;
 
   if (tls->ever_handshaked && !tls->write_closed &&
       direction & G_TLS_DIRECTION_WRITE)
     {
       status = G_TLS_CONNECTION_BASE_GET_CLASS (tls)->
-        close_fn (tls, cancellable, &close_error);
+        close_fn (tls, timeout, cancellable, &close_error);
 
       tls->write_closed = TRUE;
     }
diff --git a/tls/base/gtlsconnection-base.h b/tls/base/gtlsconnection-base.h
index 60e09cd..73329f6 100644
--- a/tls/base/gtlsconnection-base.h
+++ b/tls/base/gtlsconnection-base.h
@@ -54,9 +54,11 @@ struct _GTlsConnectionBaseClass
   GTlsConnectionClass parent_class;
 
   GTlsConnectionBaseStatus (*request_rehandshake)  (GTlsConnectionBase  *tls,
+                                                    gint64               timeout,
                                                     GCancellable        *cancellable,
                                                     GError             **error);
   GTlsConnectionBaseStatus (*handshake)            (GTlsConnectionBase  *tls,
+                                                    gint64               timeout,
                                                     GCancellable        *cancellable,
                                                     GError             **error);
   GTlsConnectionBaseStatus (*complete_handshake)   (GTlsConnectionBase  *tls,
@@ -64,7 +66,7 @@ struct _GTlsConnectionBaseClass
 
   void                     (*push_io)              (GTlsConnectionBase  *tls,
                                                     GIOCondition         direction,
-                                                    gboolean             blocking,
+                                                    gint64               timeout,
                                                     GCancellable        *cancellable);
   GTlsConnectionBaseStatus (*pop_io)               (GTlsConnectionBase  *tls,
                                                     GIOCondition         direction,
@@ -74,7 +76,7 @@ struct _GTlsConnectionBaseClass
   GTlsConnectionBaseStatus (*read_fn)              (GTlsConnectionBase  *tls,
                                                     void                *buffer,
                                                     gsize                count,
-                                                    gboolean             blocking,
+                                                    gint64               timeout,
                                                     gssize              *nread,
                                                     GCancellable        *cancellable,
                                                     GError             **error);
@@ -89,7 +91,7 @@ struct _GTlsConnectionBaseClass
   GTlsConnectionBaseStatus (*write_fn)             (GTlsConnectionBase  *tls,
                                                     const void          *buffer,
                                                     gsize                count,
-                                                    gboolean             blocking,
+                                                    gint64               timeout,
                                                     gssize              *nwrote,
                                                     GCancellable        *cancellable,
                                                     GError             **error);
@@ -102,6 +104,7 @@ struct _GTlsConnectionBaseClass
                                                     GError             **error);
 
   GTlsConnectionBaseStatus (*close_fn)             (GTlsConnectionBase  *tls,
+                                                    gint64               timeout,
                                                     GCancellable        *cancellable,
                                                     GError             **error);
 };
@@ -177,12 +180,12 @@ struct _GTlsConnectionBase
   gboolean       write_closing, write_closed;
 
   gboolean       reading;
-  gboolean       read_blocking;
+  gint64         read_timeout;
   GError        *read_error;
   GCancellable  *read_cancellable;
 
   gboolean       writing;
-  gboolean       write_blocking;
+  gint64         write_timeout;
   GError        *write_error;
   GCancellable  *write_cancellable;
 
@@ -205,7 +208,7 @@ void g_tls_connection_base_set_peer_certificate (GTlsConnectionBase   *tls,
 
 void     g_tls_connection_base_push_io       (GTlsConnectionBase *tls,
                                               GIOCondition        direction,
-                                              gboolean            blocking,
+                                              gint64              timeout,
                                               GCancellable       *cancellable);
 GTlsConnectionBaseStatus
          g_tls_connection_base_pop_io        (GTlsConnectionBase  *tls,
@@ -216,13 +219,13 @@ GTlsConnectionBaseStatus
 gssize   g_tls_connection_base_read          (GTlsConnectionBase  *tls,
                                               void                *buffer,
                                               gsize                size,
-                                              gboolean             blocking,
+                                              gint64               timeout,
                                               GCancellable        *cancellable,
                                               GError             **error);
 gssize   g_tls_connection_base_write         (GTlsConnectionBase  *tls,
                                               const void          *buffer,
                                               gsize                size,
-                                              gboolean             blocking,
+                                              gint64               timeout,
                                               GCancellable        *cancellable,
                                               GError             **error);
 
diff --git a/tls/base/gtlsinputstream-base.c b/tls/base/gtlsinputstream-base.c
index afc3bf5..771c1f1 100644
--- a/tls/base/gtlsinputstream-base.c
+++ b/tls/base/gtlsinputstream-base.c
@@ -78,7 +78,7 @@ g_tls_input_stream_base_read (GInputStream  *stream,
     }
 
   ret = g_tls_connection_base_read (conn,
-                                    buffer, count, TRUE,
+                                    buffer, count, -1 /* blocking */,
                                     cancellable, error);
   g_object_unref (conn);
   return ret;
@@ -129,7 +129,8 @@ g_tls_input_stream_base_pollable_read_nonblocking (GPollableInputStream  *pollab
   conn = g_weak_ref_get (&tls_stream->priv->weak_conn);
   g_return_val_if_fail (conn != NULL, -1);
 
-  ret = g_tls_connection_base_read (conn, buffer, size, FALSE, NULL, error);
+  ret = g_tls_connection_base_read (conn, buffer, size,
+                                    0 /* non-blocking */, NULL, error);
 
   g_object_unref (conn);
   return ret;
diff --git a/tls/base/gtlsoutputstream-base.c b/tls/base/gtlsoutputstream-base.c
index 92c0998..769515b 100644
--- a/tls/base/gtlsoutputstream-base.c
+++ b/tls/base/gtlsoutputstream-base.c
@@ -77,7 +77,7 @@ g_tls_output_stream_base_write (GOutputStream  *stream,
       return -1;
     }
 
-  ret = g_tls_connection_base_write (conn, buffer, count, TRUE,
+  ret = g_tls_connection_base_write (conn, buffer, count, -1 /* blocking */,
                                      cancellable, error);
   g_object_unref (conn);
   return ret;
@@ -131,7 +131,8 @@ g_tls_output_stream_base_pollable_write_nonblocking (GPollableOutputStream  *pol
   conn = g_weak_ref_get (&tls_stream->priv->weak_conn);
   g_return_val_if_fail (conn != NULL, -1);
 
-  ret = g_tls_connection_base_write (conn, buffer, size, FALSE, NULL, error);
+  ret = g_tls_connection_base_write (conn, buffer, size,
+                                     0 /* non-blocking */, NULL, error);
 
   g_object_unref (conn);
   return ret;
@@ -139,8 +140,8 @@ g_tls_output_stream_base_pollable_write_nonblocking (GPollableOutputStream  *pol
 
 static gboolean
 g_tls_output_stream_base_close (GOutputStream            *stream,
-                                  GCancellable             *cancellable,
-                                  GError                  **error)
+                                GCancellable             *cancellable,
+                                GError                  **error)
 {
   GTlsOutputStreamBase *tls_stream = G_TLS_OUTPUT_STREAM_BASE (stream);
   GIOStream *conn;
@@ -209,8 +210,8 @@ g_tls_output_stream_base_close_async (GOutputStream            *stream,
 
 static gboolean
 g_tls_output_stream_base_close_finish (GOutputStream            *stream,
-                                         GAsyncResult             *result,
-                                         GError                  **error)
+                                       GAsyncResult             *result,
+                                       GError                  **error)
 {
   g_return_val_if_fail (g_task_is_valid (result, stream), FALSE);
   g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) ==
diff --git a/tls/openssl/gtlsclientconnection-openssl.c b/tls/openssl/gtlsclientconnection-openssl.c
index 877d152..3e352f8 100644
--- a/tls/openssl/gtlsclientconnection-openssl.c
+++ b/tls/openssl/gtlsclientconnection-openssl.c
@@ -251,11 +251,12 @@ g_tls_client_connection_openssl_constructed (GObject *object)
 
 static GTlsConnectionBaseStatus
 g_tls_client_connection_openssl_handshake (GTlsConnectionBase  *tls,
+                                           gint64               timeout,
                                            GCancellable        *cancellable,
                                            GError             **error)
 {
   return G_TLS_CONNECTION_BASE_CLASS (g_tls_client_connection_openssl_parent_class)->
-    handshake (tls, cancellable, error);
+    handshake (tls, timeout, cancellable, error);
 }
 
 static GTlsConnectionBaseStatus
diff --git a/tls/openssl/gtlsconnection-openssl.c b/tls/openssl/gtlsconnection-openssl.c
index f268c8f..7a646ce 100644
--- a/tls/openssl/gtlsconnection-openssl.c
+++ b/tls/openssl/gtlsconnection-openssl.c
@@ -203,9 +203,9 @@ end_openssl_io (GTlsConnectionOpenssl  *openssl,
   return G_TLS_CONNECTION_BASE_ERROR;
 }
 
-#define BEGIN_OPENSSL_IO(openssl, direction, blocking, cancellable)        \
-  g_tls_connection_base_push_io (G_TLS_CONNECTION_BASE (openssl),        \
-                                 direction, blocking, cancellable);        \
+#define BEGIN_OPENSSL_IO(openssl, direction, timeout, cancellable)        \
+  g_tls_connection_base_push_io (G_TLS_CONNECTION_BASE (openssl),         \
+                                 direction, timeout, cancellable);         \
   do {                                                                      \
     char error_str[256];
 
@@ -216,6 +216,7 @@ end_openssl_io (GTlsConnectionOpenssl  *openssl,
 
 static GTlsConnectionBaseStatus
 g_tls_connection_openssl_request_rehandshake (GTlsConnectionBase  *tls,
+                                              gint64               timeout,
                                               GCancellable        *cancellable,
                                               GError             **error)
 {
@@ -242,7 +243,7 @@ g_tls_connection_openssl_request_rehandshake (GTlsConnectionBase  *tls,
 
   ssl = g_tls_connection_openssl_get_ssl (openssl);
 
-  BEGIN_OPENSSL_IO (openssl, G_IO_IN | G_IO_OUT, TRUE, cancellable);
+  BEGIN_OPENSSL_IO (openssl, G_IO_IN | G_IO_OUT, timeout, cancellable);
   ret = SSL_renegotiate (ssl);
   END_OPENSSL_IO (openssl, G_IO_IN | G_IO_OUT, ret, status,
                   _("Error performing TLS handshake: %s"), error);
@@ -362,6 +363,7 @@ verify_peer_certificate (GTlsConnectionOpenssl *openssl,
 
 static GTlsConnectionBaseStatus
 g_tls_connection_openssl_handshake (GTlsConnectionBase  *tls,
+                                    gint64               timeout,
                                     GCancellable        *cancellable,
                                     GError             **error)
 {
@@ -375,7 +377,7 @@ g_tls_connection_openssl_handshake (GTlsConnectionBase  *tls,
 
   ssl = g_tls_connection_openssl_get_ssl (openssl);
 
-  BEGIN_OPENSSL_IO (openssl, G_IO_IN | G_IO_OUT, TRUE, cancellable);
+  BEGIN_OPENSSL_IO (openssl, G_IO_IN | G_IO_OUT, timeout, cancellable);
   ret = SSL_do_handshake (ssl);
   END_OPENSSL_IO (openssl, G_IO_IN | G_IO_OUT, ret, status,
                   _("Error performing TLS handshake: %s"), error);
@@ -434,7 +436,7 @@ g_tls_connection_openssl_complete_handshake (GTlsConnectionBase  *tls,
 static void
 g_tls_connection_openssl_push_io (GTlsConnectionBase *tls,
                                   GIOCondition        direction,
-                                  gboolean            blocking,
+                                  gint64              timeout,
                                   GCancellable       *cancellable)
 {
   GTlsConnectionOpenssl *openssl = G_TLS_CONNECTION_OPENSSL (tls);
@@ -443,12 +445,15 @@ g_tls_connection_openssl_push_io (GTlsConnectionBase *tls,
   priv = g_tls_connection_openssl_get_instance_private (openssl);
 
   G_TLS_CONNECTION_BASE_CLASS (g_tls_connection_openssl_parent_class)->push_io (tls, direction,
-                                                                                blocking, cancellable);
+                                                                                timeout, cancellable);
+
+  /* FIXME: need to support timeout > 0
+   * This will require changes in GTlsBio */
 
   if (direction & G_IO_IN)
     {
       g_tls_bio_set_read_cancellable (priv->bio, cancellable);
-      g_tls_bio_set_read_blocking (priv->bio, blocking);
+      g_tls_bio_set_read_blocking (priv->bio, timeout == -1);
       g_clear_error (&tls->read_error);
       g_tls_bio_set_read_error (priv->bio, &tls->read_error);
     }
@@ -456,7 +461,7 @@ g_tls_connection_openssl_push_io (GTlsConnectionBase *tls,
   if (direction & G_IO_OUT)
     {
       g_tls_bio_set_write_cancellable (priv->bio, cancellable);
-      g_tls_bio_set_write_blocking (priv->bio, blocking);
+      g_tls_bio_set_write_blocking (priv->bio, timeout == -1);
       g_clear_error (&tls->write_error);
       g_tls_bio_set_write_error (priv->bio, &tls->write_error);
     }
@@ -487,7 +492,7 @@ static GTlsConnectionBaseStatus
 g_tls_connection_openssl_read (GTlsConnectionBase    *tls,
                                void                  *buffer,
                                gsize                  count,
-                               gboolean               blocking,
+                               gint64                 timeout,
                                gssize                *nread,
                                GCancellable          *cancellable,
                                GError               **error)
@@ -499,7 +504,7 @@ g_tls_connection_openssl_read (GTlsConnectionBase    *tls,
 
   ssl = g_tls_connection_openssl_get_ssl (openssl);
 
-  BEGIN_OPENSSL_IO (openssl, G_IO_IN, blocking, cancellable);
+  BEGIN_OPENSSL_IO (openssl, G_IO_IN, timeout, cancellable);
   ret = SSL_read (ssl, buffer, count);
   END_OPENSSL_IO (openssl, G_IO_IN, ret, status,
                   _("Error reading data from TLS socket: %s"), error);
@@ -513,7 +518,7 @@ static GTlsConnectionBaseStatus
 g_tls_connection_openssl_write (GTlsConnectionBase    *tls,
                                 const void            *buffer,
                                 gsize                  count,
-                                gboolean               blocking,
+                                gint64                 timeout,
                                 gssize                *nwrote,
                                 GCancellable          *cancellable,
                                 GError               **error)
@@ -525,7 +530,7 @@ g_tls_connection_openssl_write (GTlsConnectionBase    *tls,
 
   ssl = g_tls_connection_openssl_get_ssl (openssl);
 
-  BEGIN_OPENSSL_IO (openssl, G_IO_OUT, blocking, cancellable);
+  BEGIN_OPENSSL_IO (openssl, G_IO_OUT, timeout, cancellable);
   ret = SSL_write (ssl, buffer, count);
   END_OPENSSL_IO (openssl, G_IO_OUT, ret, status,
                   _("Error writing data to TLS socket: %s"), error);
@@ -537,6 +542,7 @@ g_tls_connection_openssl_write (GTlsConnectionBase    *tls,
 
 static GTlsConnectionBaseStatus
 g_tls_connection_openssl_close (GTlsConnectionBase  *tls,
+                                gint64               timeout,
                                 GCancellable        *cancellable,
                                 GError             **error)
 {
@@ -551,7 +557,7 @@ g_tls_connection_openssl_close (GTlsConnectionBase  *tls,
 
   priv->shutting_down = TRUE;
 
-  BEGIN_OPENSSL_IO (openssl, G_IO_IN | G_IO_OUT, TRUE, cancellable);
+  BEGIN_OPENSSL_IO (openssl, G_IO_IN | G_IO_OUT, timeout, cancellable);
   ret = SSL_shutdown (ssl);
   END_OPENSSL_IO (openssl, G_IO_IN | G_IO_OUT, ret, status,
                   _("Error performing TLS close: %s"), error);
diff --git a/tls/openssl/gtlsserverconnection-openssl.c b/tls/openssl/gtlsserverconnection-openssl.c
index a59175b..2609bb6 100644
--- a/tls/openssl/gtlsserverconnection-openssl.c
+++ b/tls/openssl/gtlsserverconnection-openssl.c
@@ -189,6 +189,7 @@ verify_callback (int             preverify_ok,
 
 static GTlsConnectionBaseStatus
 g_tls_server_connection_openssl_handshake (GTlsConnectionBase  *tls,
+                                           gint64               timeout,
                                            GCancellable        *cancellable,
                                            GError             **error)
 {
@@ -216,7 +217,7 @@ g_tls_server_connection_openssl_handshake (GTlsConnectionBase  *tls,
   SSL_set_verify_depth (priv->ssl, 0);
 
   return G_TLS_CONNECTION_BASE_CLASS (g_tls_server_connection_openssl_parent_class)->
-    handshake (tls, cancellable, error);
+    handshake (tls, timeout, cancellable, error);
 }
 
 static SSL *


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