[glib-networking/mcatanzaro/tls-thread: 4/19] progress
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib-networking/mcatanzaro/tls-thread: 4/19] progress
- Date: Sat, 10 Aug 2019 00:42:58 +0000 (UTC)
commit bb2f57e67fd56e2f58115cd7a0dfc9279dd0fede
Author: Michael Catanzaro <mcatanzaro igalia com>
Date: Wed Jul 24 15:57:46 2019 -0500
progress
tls/base/gtlsconnection-base.c | 10 ++++----
tls/base/gtlsconnection-base.h | 6 +++--
tls/base/gtlsthread.c | 48 +++++++++++++++++++-----------------
tls/base/gtlsthread.h | 17 +++++++------
tls/gnutls/gtlsconnection-gnutls.c | 8 +++---
tls/openssl/gtlsconnection-openssl.c | 8 +++---
6 files changed, 52 insertions(+), 45 deletions(-)
---
diff --git a/tls/base/gtlsconnection-base.c b/tls/base/gtlsconnection-base.c
index fd424a0..8e34883 100644
--- a/tls/base/gtlsconnection-base.c
+++ b/tls/base/gtlsconnection-base.c
@@ -1817,7 +1817,7 @@ do_implicit_handshake (GTlsConnectionBase *tls,
gssize
g_tls_connection_base_read (GTlsConnectionBase *tls,
void *buffer,
- gsize count,
+ gsize size,
gint64 timeout,
GCancellable *cancellable,
GError **error)
@@ -1834,7 +1834,7 @@ g_tls_connection_base_read (GTlsConnectionBase *tls,
if (priv->app_data_buf && !priv->handshaking)
{
- nread = MIN (count, priv->app_data_buf->len);
+ nread = MIN (size, priv->app_data_buf->len);
memcpy (buffer, priv->app_data_buf->data, nread);
if (nread == priv->app_data_buf->len)
g_clear_pointer (&priv->app_data_buf, g_byte_array_unref);
@@ -1845,7 +1845,7 @@ g_tls_connection_base_read (GTlsConnectionBase *tls,
else
{
status = G_TLS_CONNECTION_BASE_GET_CLASS (tls)->
- read_fn (tls, buffer, count, timeout, &nread, cancellable, error);
+ read_fn (tls, buffer, size, timeout, &nread, cancellable, error);
}
yield_op (tls, G_TLS_CONNECTION_BASE_OP_READ, status);
@@ -1998,7 +1998,7 @@ g_tls_connection_base_receive_messages (GDatagramBased *datagram_based,
gssize
g_tls_connection_base_write (GTlsConnectionBase *tls,
const void *buffer,
- gsize count,
+ gsize size,
gint64 timeout,
GCancellable *cancellable,
GError **error)
@@ -2014,7 +2014,7 @@ g_tls_connection_base_write (GTlsConnectionBase *tls,
return -1;
status = G_TLS_CONNECTION_BASE_GET_CLASS (tls)->
- write_fn (tls, buffer, count, timeout, &nwrote, cancellable, error);
+ write_fn (tls, buffer, size, timeout, &nwrote, cancellable, error);
yield_op (tls, G_TLS_CONNECTION_BASE_OP_WRITE, status);
}
diff --git a/tls/base/gtlsconnection-base.h b/tls/base/gtlsconnection-base.h
index fb854eb..3e27ad2 100644
--- a/tls/base/gtlsconnection-base.h
+++ b/tls/base/gtlsconnection-base.h
@@ -93,7 +93,7 @@ struct _GTlsConnectionBaseClass
GTlsConnectionBaseStatus (*read_fn) (GTlsConnectionBase *tls,
void *buffer,
- gsize count,
+ gsize size,
gint64 timeout,
gssize *nread,
GCancellable *cancellable,
@@ -108,7 +108,7 @@ struct _GTlsConnectionBaseClass
GTlsConnectionBaseStatus (*write_fn) (GTlsConnectionBase *tls,
const void *buffer,
- gsize count,
+ gsize size,
gint64 timeout,
gssize *nwrote,
GCancellable *cancellable,
@@ -197,6 +197,8 @@ void g_tls_connection_base_handshake_thread_buffer_applicat
guint8 *data,
gsize length);
+
+
void GTLS_DEBUG (gpointer connection,
const char *message,
...);
diff --git a/tls/base/gtlsthread.c b/tls/base/gtlsthread.c
index 027ed6a..9268632 100644
--- a/tls/base/gtlsthread.c
+++ b/tls/base/gtlsthread.c
@@ -60,6 +60,8 @@
*/
struct _GTlsThread {
GObject parent_instance;
+
+ GTlsConnectionBase *connection; /* unowned */
GThread *thread;
GAsyncQueue *queue;
};
@@ -82,9 +84,12 @@ typedef struct {
enum
{
PROP_0,
- PROP_CONNECTION,
+ PROP_TLS_CONNECTION,
+ LAST_PROP
};
+static GParamSpec *obj_properties[LAST_PROP];
+
G_DEFINE_TYPE (GTlsThread, g_tls_thread, G_TYPE_TLS_THREAD)
static GTlsThreadOperation *
@@ -123,7 +128,6 @@ g_tls_thread_shutdown_operation_new (void)
static void
g_tls_thread_operation_free (GTlsThreadOperation *op)
{
- g_clear_pointer (&op->data, g_free);
g_clear_object (&op->cancellable);
g_clear_pointer (&op->main_loop, g_main_loop_unref);
g_free (op);
@@ -148,7 +152,6 @@ g_tls_thread_read (GTlsThread *self,
cancellable, main_loop);
g_async_queue_push (self->queue, op);
- /* FIXME: must respect timeout somehow */
g_main_loop_run (main_loop);
/* FIXME: do something with op->result */
@@ -176,6 +179,7 @@ tls_thread (gpointer data)
{
case G_TLS_THREAD_OP_READ:
/* FIXME: handle this */
+ /* FIXME: must respect timeout somehow */
break;
case G_TLS_THREAD_OP_SHUTDOWN:
break;
@@ -200,12 +204,11 @@ g_tls_thread_get_property (GObject *object,
GParamSpec *pspec)
{
GTlsThread *self = G_TLS_THREAD (object);
- GTlsBackend *backend;
switch (prop_id)
{
- case PROP_BASE_IO_STREAM:
- g_value_set_object (value, priv->base_io_stream);
+ case PROP_TLS_CONNECTION:
+ g_value_set_object (value, self->connection);
break;
default:
@@ -214,25 +217,17 @@ g_tls_thread_get_property (GObject *object,
}
static void
-g_tls_connection_base_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+g_tls_thread_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- GTlsConnectionBase *tls = G_TLS_CONNECTION_BASE (object);
- GTlsConnectionBasePrivate *priv = g_tls_connection_base_get_instance_private (tls);
- GInputStream *istream;
- GOutputStream *ostream;
- gboolean system_certdb;
- GTlsBackend *backend;
+ GTlsThread *self = G_TLS_THREAD (object);
switch (prop_id)
{
- case PROP_BASE_SOCKET:
- g_assert (!g_value_get_object (value) || !priv->base_io_stream);
-
- g_clear_object (&priv->base_socket);
- priv->base_socket = g_value_dup_object (value);
+ case PROP_TLS_CONNECTION:
+ self->connection = g_value_get_object (value);
break;
default:
@@ -270,6 +265,15 @@ g_tls_thread_class_init (GTlsThreadClass *klass)
gobject_class->dispose = g_tls_thread_dispose;
gobject_class->get_property = g_tls_thread_get_property;
gobject_class->set_property = g_tls_thread_set_property;
+
+ obj_properties[PROP_TLS_CONNECTION] =
+ g_param_spec_object ("tls-connection",
+ "TLS Connection",
+ "The thread's GTlsConnection",
+ G_TYPE_TLS_CONNECTION_BASE,
+ G_PARAM_READABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (gobject_class, LAST_PROP, obj_properties);
}
GTlsThread *
@@ -278,7 +282,7 @@ g_tls_thread_new (GTlsConnectionBase *tls)
GTlsThread *thread;
thread = g_object_new (G_TYPE_TLS_THREAD,
- "connection", tls,
+ "tls-connection", tls,
NULL);
return thread;
diff --git a/tls/base/gtlsthread.h b/tls/base/gtlsthread.h
index cf56dd6..95fc756 100644
--- a/tls/base/gtlsthread.h
+++ b/tls/base/gtlsthread.h
@@ -34,13 +34,14 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GTlsThread, g_tls_thread, G, TLS_THREAD, GObject)
-GTlsThread *g_tls_thread_new (GTlsConnectionBase *tls);
-
-gssize g_tls_thread_base_read (GTlsThread *self,
- void *buffer,
- gsize size,
- gint64 timeout,
- GCancellable *cancellable,
- GError **error);
+GTlsThread *g_tls_thread_new (GTlsConnectionBase *tls);
+
+GTlsConnectionBaseStatus g_tls_thread_read (GTlsThread *self,
+ void *buffer,
+ gsize size,
+ gint64 timeout,
+ gssize *nread,
+ GCancellable *cancellable,
+ GError **error);
G_END_DECLS
diff --git a/tls/gnutls/gtlsconnection-gnutls.c b/tls/gnutls/gtlsconnection-gnutls.c
index 4a5b2c4..7cd4e0c 100644
--- a/tls/gnutls/gtlsconnection-gnutls.c
+++ b/tls/gnutls/gtlsconnection-gnutls.c
@@ -924,7 +924,7 @@ g_tls_connection_gnutls_is_session_resumed (GTlsConnectionBase *tls)
static GTlsConnectionBaseStatus
g_tls_connection_gnutls_read (GTlsConnectionBase *tls,
void *buffer,
- gsize count,
+ gsize size,
gint64 timeout,
gssize *nread,
GCancellable *cancellable,
@@ -936,7 +936,7 @@ g_tls_connection_gnutls_read (GTlsConnectionBase *tls,
gssize ret;
BEGIN_GNUTLS_IO (gnutls, G_IO_IN, timeout, cancellable);
- ret = gnutls_record_recv (priv->session, buffer, count);
+ ret = gnutls_record_recv (priv->session, buffer, size);
END_GNUTLS_IO (gnutls, G_IO_IN, ret, status, _("Error reading data from TLS socket"), error);
*nread = MAX (ret, 0);
@@ -1006,7 +1006,7 @@ g_tls_connection_gnutls_read_message (GTlsConnectionBase *tls,
static GTlsConnectionBaseStatus
g_tls_connection_gnutls_write (GTlsConnectionBase *tls,
const void *buffer,
- gsize count,
+ gsize size,
gint64 timeout,
gssize *nwrote,
GCancellable *cancellable,
@@ -1018,7 +1018,7 @@ g_tls_connection_gnutls_write (GTlsConnectionBase *tls,
gssize ret;
BEGIN_GNUTLS_IO (gnutls, G_IO_OUT, timeout, cancellable);
- ret = gnutls_record_send (priv->session, buffer, count);
+ ret = gnutls_record_send (priv->session, buffer, size);
END_GNUTLS_IO (gnutls, G_IO_OUT, ret, status, _("Error writing data to TLS socket"), error);
*nwrote = MAX (ret, 0);
diff --git a/tls/openssl/gtlsconnection-openssl.c b/tls/openssl/gtlsconnection-openssl.c
index f07be5a..331c3cf 100644
--- a/tls/openssl/gtlsconnection-openssl.c
+++ b/tls/openssl/gtlsconnection-openssl.c
@@ -392,7 +392,7 @@ g_tls_connection_openssl_pop_io (GTlsConnectionBase *tls,
static GTlsConnectionBaseStatus
g_tls_connection_openssl_read (GTlsConnectionBase *tls,
void *buffer,
- gsize count,
+ gsize size,
gint64 timeout,
gssize *nread,
GCancellable *cancellable,
@@ -419,7 +419,7 @@ g_tls_connection_openssl_read (GTlsConnectionBase *tls,
g_tls_connection_base_push_io (G_TLS_CONNECTION_BASE (openssl),
G_IO_IN, 0, cancellable);
- ret = SSL_read (ssl, buffer, count);
+ ret = SSL_read (ssl, buffer, size);
ERR_error_string_n (SSL_get_error (ssl, ret), error_str, sizeof (error_str));
status = end_openssl_io (openssl, G_IO_IN, ret, timeout == -1, error,
@@ -439,7 +439,7 @@ g_tls_connection_openssl_read (GTlsConnectionBase *tls,
static GTlsConnectionBaseStatus
g_tls_connection_openssl_write (GTlsConnectionBase *tls,
const void *buffer,
- gsize count,
+ gsize size,
gint64 timeout,
gssize *nwrote,
GCancellable *cancellable,
@@ -463,7 +463,7 @@ g_tls_connection_openssl_write (GTlsConnectionBase *tls,
g_tls_connection_base_push_io (G_TLS_CONNECTION_BASE (openssl),
G_IO_OUT, 0, cancellable);
- ret = SSL_write (ssl, buffer, count);
+ 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, timeout == -1, error,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]