[glib-networking/mcatanzaro/tls-thread: 8/14] progress
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib-networking/mcatanzaro/tls-thread: 8/14] progress
- Date: Sat, 14 Dec 2019 20:22:32 +0000 (UTC)
commit 6963790ef10072a11567762c89d57644c2ebe18c
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Wed Dec 4 14:07:29 2019 -0600
progress
tls/base/gtlsconnection-base.c | 26 +++++++++---
tls/base/gtlsoperationsthread-base.c | 1 -
tls/base/gtlsoperationsthread-base.h | 4 +-
tls/gnutls/gtlsoperationsthread-gnutls.c | 8 ++--
tls/gnutls/gtlsoperationsthread-gnutls.h | 4 +-
tls/openssl/gtlsoperationsthread-openssl.c | 68 ++++++++++--------------------
tls/openssl/gtlsoperationsthread-openssl.h | 4 +-
7 files changed, 53 insertions(+), 62 deletions(-)
---
diff --git a/tls/base/gtlsconnection-base.c b/tls/base/gtlsconnection-base.c
index 84cfe0a..ef70122 100644
--- a/tls/base/gtlsconnection-base.c
+++ b/tls/base/gtlsconnection-base.c
@@ -187,6 +187,8 @@ static gboolean g_tls_connection_base_handshake (GTlsConnection *conn,
GCancellable *cancellable,
GError **error);
+static GInitableIface *g_tls_connection_base_parent_initable_iface;
+
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GTlsConnectionBase, g_tls_connection_base, G_TYPE_TLS_CONNECTION,
G_ADD_PRIVATE (GTlsConnectionBase);
G_IMPLEMENT_INTERFACE (G_TYPE_DATAGRAM_BASED,
@@ -240,15 +242,20 @@ g_tls_connection_base_init (GTlsConnectionBase *tls)
priv->waiting_for_op = g_cancellable_new ();
}
-static void
-g_tls_connection_base_constructed (GObject *object)
+static gboolean
+g_tls_connection_base_initable_init (GInitable *initable,
+ GCancellable *cancellable,
+ GError **error)
{
- GTlsConnectionBase *tls = G_TLS_CONNECTION_BASE (object);
+ GTlsConnectionBase *tls = G_TLS_CONNECTION_BASE (initable);
GTlsConnectionBasePrivate *priv = g_tls_connection_base_get_instance_private (tls);
- G_OBJECT_CLASS (g_tls_connection_base_parent_class)->constructed (object);
-
priv->thread = G_TLS_CONNECTION_BASE_GET_CLASS (tls)->create_op_thread (tls);
+
+ if (!g_tls_connection_base_parent_initable_iface->init (initable, cancellable, error))
+ return FALSE;
+
+ return TRUE;
}
static void
@@ -2691,7 +2698,6 @@ g_tls_connection_base_class_init (GTlsConnectionBaseClass *klass)
gobject_class->get_property = g_tls_connection_base_get_property;
gobject_class->set_property = g_tls_connection_base_set_property;
- gobject_class->constructed = g_tls_connection_base_constructed;
gobject_class->finalize = g_tls_connection_base_finalize;
connection_class->handshake = g_tls_connection_base_handshake;
@@ -2744,3 +2750,11 @@ g_tls_connection_base_datagram_based_iface_init (GDatagramBasedInterface *iface)
iface->condition_check = g_tls_connection_base_condition_check;
iface->condition_wait = g_tls_connection_base_condition_wait;
}
+
+static void
+g_tls_client_connection_base_initable_interface_init (GInitableIface *iface)
+{
+ g_tls_connection_base_parent_initable_iface = g_type_interface_peek_parent (iface);
+
+ iface->init = g_tls_connection_base_initable_init;
+}
diff --git a/tls/base/gtlsoperationsthread-base.c b/tls/base/gtlsoperationsthread-base.c
index ce3e120..6d1d642 100644
--- a/tls/base/gtlsoperationsthread-base.c
+++ b/tls/base/gtlsoperationsthread-base.c
@@ -24,7 +24,6 @@
*/
#include "config.h"
-
#include "gtlsoperationsthread-base.h"
#include <glib/gi18n-lib.h>
diff --git a/tls/base/gtlsoperationsthread-base.h b/tls/base/gtlsoperationsthread-base.h
index 6962c85..e910f01 100644
--- a/tls/base/gtlsoperationsthread-base.h
+++ b/tls/base/gtlsoperationsthread-base.h
@@ -24,10 +24,10 @@
#pragma once
-#include <gio/gio.h>
-
#include "gtlsconnection-base.h"
+#include <gio/gio.h>
+
G_BEGIN_DECLS
#define G_TYPE_TLS_OPERATIONS_THREAD_BASE (g_tls_operations_thread_base_get_type ())
diff --git a/tls/gnutls/gtlsoperationsthread-gnutls.c b/tls/gnutls/gtlsoperationsthread-gnutls.c
index 81b118b..e0aaf6c 100644
--- a/tls/gnutls/gtlsoperationsthread-gnutls.c
+++ b/tls/gnutls/gtlsoperationsthread-gnutls.c
@@ -26,13 +26,13 @@
*/
#include "config.h"
+#include "gtlsoperationsthread-gnutls.h"
+
+#include "gtlsconnection-gnutls.h"
#include <glib/gi18n-lib.h>
#include <gnutls/dtls.h>
-#include "gtlsoperationsthread-gnutls.h"
-#include "gtlsconnection-gnutls.h"
-
struct _GTlsOperationsThreadGnutls {
GTlsOperationsThreadBase parent_instance;
@@ -372,7 +372,7 @@ g_tls_operations_thread_gnutls_write_message (GTlsOperationsThreadBase *base,
static void
g_tls_operations_thread_gnutls_constructed (GObject *object)
{
- GTlsOperationsThreadGnutls *self = G_TYPE_TLS_OPERATIONS_THREAD_GNUTLS (object);
+ GTlsOperationsThreadGnutls *self = G_TLS_OPERATIONS_THREAD_GNUTLS (object);
GTlsConnectionBase *tls;
G_OBJECT_CLASS (g_tls_operations_thread_gnutls_parent_class)->constructed (object);
diff --git a/tls/gnutls/gtlsoperationsthread-gnutls.h b/tls/gnutls/gtlsoperationsthread-gnutls.h
index 8a0acad..b3fce2d 100644
--- a/tls/gnutls/gtlsoperationsthread-gnutls.h
+++ b/tls/gnutls/gtlsoperationsthread-gnutls.h
@@ -24,11 +24,11 @@
#pragma once
-#include <gio/gio.h>
-
#include "gtlsconnection-gnutls.h"
#include "gtlsoperationsthread-base.h"
+#include <gio/gio.h>
+
G_BEGIN_DECLS
#define G_TYPE_TLS_OPERATIONS_THREAD_GNUTLS (g_tls_operations_thread_gnutls_get_type ())
diff --git a/tls/openssl/gtlsoperationsthread-openssl.c b/tls/openssl/gtlsoperationsthread-openssl.c
index 43f4ca4..7e5d4b1 100644
--- a/tls/openssl/gtlsoperationsthread-openssl.c
+++ b/tls/openssl/gtlsoperationsthread-openssl.c
@@ -25,11 +25,11 @@
*/
#include "config.h"
-
-#include <glib/gi18n-lib.h>
+#include "gtlsoperationsthread-openssl.h"
#include "gtlsconnection-openssl.h"
-#include "gtlsoperationsthread-openssl.h"
+
+#include <glib/gi18n-lib.h>
struct _GTlsOperationsThreadOpenssl {
GTlsOperationsThreadBase parent_instance;
@@ -170,6 +170,7 @@ end_openssl_io (GTlsOperationsThreadOpenssl *self,
return G_TLS_CONNECTION_BASE_ERROR;
}
+// FIXME: remove timeout params
#define BEGIN_OPENSSL_IO(self, direction, timeout, cancellable) \
do { \
char error_str[256]; \
@@ -189,14 +190,14 @@ g_tls_operations_thread_openssl_read (GTlsOperationsThreadBase *base,
GCancellable *cancellable,
GError **error)
{
- GTlsOperationsThreadOpenssl *self = G_TYPE_TLS_OPERATIONS_THREAD_OPENSSL (base);
+ GTlsOperationsThreadOpenssl *self = G_TLS_OPERATIONS_THREAD_OPENSSL (base);
GTlsConnectionBaseStatus status;
gssize ret;
- BEGIN_OPENSSL_IO (self, G_IO_OUT, timeout, cancellable);
- ret = SSL_write (self->ssl, buffer, count);
- END_OPENSSL_IO (self, G_IO_OUT, ret, status,
- _("Error writing data to TLS socket"), error);
+ BEGIN_OPENSSL_IO (self, G_IO_OUT, 0, cancellable);
+ ret = SSL_read (self->ssl, buffer, size);
+ END_OPENSSL_IO (self, G_IO_OUT, ret, 0, status,
+ _("Error reading data from TLS socket"), error);
*nread = MAX (ret, 0);
@@ -204,44 +205,21 @@ g_tls_operations_thread_openssl_read (GTlsOperationsThreadBase *base,
}
static GTlsConnectionBaseStatus
-g_tls_connection_openssl_write (GTlsConnectionBase *tls,
- const void *buffer,
- gsize size,
- gssize *nwrote,
- GCancellable *cancellable,
- GError **error)
+g_tls_operations_thread_openssl_write (GTlsOperationsThreadBase *base,
+ const void *buffer,
+ gsize size,
+ gssize *nwrote,
+ GCancellable *cancellable,
+ GError **error)
{
- GTlsConnectionOpenssl *openssl = G_TLS_CONNECTION_OPENSSL (tls);
- GTlsConnectionOpensslPrivate *priv;
+ GTlsOperationsThreadOpenssl *self = G_TLS_OPERATIONS_THREAD_OPENSSL (base);
GTlsConnectionBaseStatus status;
- SSL *ssl;
gssize ret;
- priv = g_tls_connection_openssl_get_instance_private (openssl);
-
- ssl = g_tls_connection_openssl_get_ssl (openssl);
-
- while (TRUE)
- {
- char error_str[256];
-
- /* We want to always be non blocking here to avoid deadlocks */
- g_tls_connection_base_push_io (G_TLS_CONNECTION_BASE (openssl),
- G_IO_OUT, 0, cancellable);
-
- ret = SSL_write (ssl, buffer, size);
-
- ERR_error_string_n (SSL_get_error (ssl, ret), error_str, sizeof (error_str));
- status = end_openssl_io (openssl, G_IO_OUT, ret, FALSE, error,
- _("Error writing data to TLS socket"), error_str);
-
- if (status != G_TLS_CONNECTION_BASE_TRY_AGAIN)
- break;
-
- /* Wait for the socket to be available again to avoid an infinite loop */
- g_tls_bio_wait_available (priv->bio, G_IO_OUT, cancellable);
- }
-
+ BEGIN_OPENSSL_IO (self, G_IO_OUT, 0, cancellable);
+ ret = SSL_write (self->ssl, buffer, size);
+ END_OPENSSL_IO (self, G_IO_OUT, ret, 0, status,
+ _("Error writing data to TLS socket"), error);
*nwrote = MAX (ret, 0);
return status;
}
@@ -249,13 +227,13 @@ g_tls_connection_openssl_write (GTlsConnectionBase *tls,
static void
g_tls_operations_thread_openssl_constructed (GObject *object)
{
- GTlsOperationsThreadOpenssl *self = G_TYPE_TLS_OPERATIONS_THREAD_OPENSSL (object);
- GTlsConnectionOpenssl *openssl;
+ GTlsOperationsThreadOpenssl *self = G_TLS_OPERATIONS_THREAD_OPENSSL (object);
+ GTlsConnectionBase *openssl;
G_OBJECT_CLASS (g_tls_operations_thread_openssl_parent_class)->constructed (object);
openssl = g_tls_operations_thread_base_get_connection (G_TLS_OPERATIONS_THREAD_BASE (self));
- self->ssl = g_tls_connection_openssl_get_ssl (openssl);
+ self->ssl = g_tls_connection_openssl_get_ssl (G_TLS_CONNECTION_OPENSSL (openssl));
}
static void
diff --git a/tls/openssl/gtlsoperationsthread-openssl.h b/tls/openssl/gtlsoperationsthread-openssl.h
index 730bf75..da6daa4 100644
--- a/tls/openssl/gtlsoperationsthread-openssl.h
+++ b/tls/openssl/gtlsoperationsthread-openssl.h
@@ -24,11 +24,11 @@
#pragma once
-#include <gio/gio.h>
-
#include "gtlsconnection-openssl.h"
#include "gtlsoperationsthread-base.h"
+#include <gio/gio.h>
+
G_BEGIN_DECLS
#define G_TYPE_TLS_OPERATIONS_THREAD_OPENSSL (g_tls_operations_thread_openssl_get_type ())
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]