[glib-networking/wip/openssl] Retry read or write if the opeartion would block



commit c611d25dbdd91d6d45530f3afe5f9ac3e753eeb7
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Thu Jan 21 10:14:05 2016 +0100

    Retry read or write if the opeartion would block

 tls/openssl/gtlsbio.c |   45 ++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 38 insertions(+), 7 deletions(-)
---
diff --git a/tls/openssl/gtlsbio.c b/tls/openssl/gtlsbio.c
index dad0d75..0a3860c 100644
--- a/tls/openssl/gtlsbio.c
+++ b/tls/openssl/gtlsbio.c
@@ -113,17 +113,33 @@ gtls_bio_write (BIO        *bio,
                 int         inl)
 {
   GTlsBio *gbio;
+  gssize written;
+  GError *error = NULL;
 
   if (!bio->init || in == NULL || inl == 0)
     return 0;
 
   gbio = (GTlsBio *)bio->ptr;
 
-  return g_pollable_stream_write (g_io_stream_get_output_stream (gbio->io_stream),
-                                  in, inl,
-                                  gbio->write_blocking,
-                                  gbio->write_cancellable,
-                                  gbio->write_error);
+  BIO_clear_retry_flags (bio);
+  written = g_pollable_stream_write (g_io_stream_get_output_stream (gbio->io_stream),
+                                     in, inl,
+                                     gbio->write_blocking,
+                                     gbio->write_cancellable,
+                                     &error);
+
+  if (written == -1)
+    {
+      if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK))
+        {
+          BIO_set_retry_write (bio);
+          g_error_free (error);
+        }
+      else
+        g_propagate_error (gbio->write_error, error);
+    }
+
+  return written;
 }
 
 static int
@@ -132,17 +148,32 @@ gtls_bio_read (BIO  *bio,
                int   outl)
 {
   GTlsBio *gbio;
+  gssize read;
+  GError *error = NULL;
 
   if (!bio->init || out == NULL || outl == 0)
     return 0;
 
   gbio = (GTlsBio *)bio->ptr;
 
-  return g_pollable_stream_read (g_io_stream_get_input_stream (gbio->io_stream),
+  read = g_pollable_stream_read (g_io_stream_get_input_stream (gbio->io_stream),
                                  out, outl,
                                  gbio->read_blocking,
                                  gbio->read_cancellable,
-                                 gbio->read_error);
+                                 &error);
+
+  if (read == -1)
+    {
+      if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK))
+        {
+          BIO_set_retry_read (bio);
+          g_error_free (error);
+        }
+      else
+        g_propagate_error (gbio->read_error, error);
+    }
+
+  return read;
 }
 
 static int


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