[glib-networking/mcatanzaro/tls-thread] progress???
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib-networking/mcatanzaro/tls-thread] progress???
- Date: Sun, 11 Aug 2019 18:05:34 +0000 (UTC)
commit c525168f823c636e313c0454bd5564ef8bfe1473
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Sat Aug 10 16:18:21 2019 -0500
progress???
tls/base/gtlsconnection-base.c | 3 +++
tls/base/gtlsthread.c | 41 +++++++++++++++++++++++++-------
tls/gnutls/gtlsclientconnection-gnutls.c | 3 +++
tls/gnutls/gtlsconnection-gnutls.c | 3 ++-
tls/tests/connection.c | 12 ++++++++++
5 files changed, 53 insertions(+), 9 deletions(-)
---
diff --git a/tls/base/gtlsconnection-base.c b/tls/base/gtlsconnection-base.c
index 812461f..f900f30 100644
--- a/tls/base/gtlsconnection-base.c
+++ b/tls/base/gtlsconnection-base.c
@@ -1826,6 +1826,7 @@ g_tls_connection_base_read (GTlsConnectionBase *tls,
GTlsConnectionBasePrivate *priv = g_tls_connection_base_get_instance_private (tls);
GTlsConnectionBaseStatus status;
gssize nread;
+GTLS_DEBUG (tls, "%s: timeout=%ld", __FUNCTION__, timeout);
do
{
@@ -1845,7 +1846,9 @@ g_tls_connection_base_read (GTlsConnectionBase *tls,
}
else
{
+GTLS_DEBUG (tls, "%s: Entering TLS thread read...", __FUNCTION__);
status = g_tls_thread_read (priv->thread, buffer, size, timeout, &nread, cancellable, error);
+GTLS_DEBUG (tls, "%s: Completed TLS thread read, status=%d nread=%zd", __FUNCTION__, status, nread);
}
yield_op (tls, G_TLS_CONNECTION_BASE_OP_READ, status);
diff --git a/tls/base/gtlsthread.c b/tls/base/gtlsthread.c
index da93672..5b16951 100644
--- a/tls/base/gtlsthread.c
+++ b/tls/base/gtlsthread.c
@@ -28,6 +28,7 @@
#include "gtlsthread.h"
#include <glib/gi18n-lib.h>
+#include <glib/gstdio.h>
/* The purpose of this class is to ensure the underlying TLS library is only
* ever used on a single thread. There are multiple benefits of this:
@@ -178,6 +179,7 @@ g_tls_thread_read (GTlsThread *self,
GTlsThreadOperation *op;
GMainContext *main_context;
GMainLoop *main_loop;
+ GTlsConnectionBaseStatus result;
main_context = g_main_context_new ();
main_loop = g_main_loop_new (main_context, FALSE);
@@ -187,7 +189,7 @@ g_tls_thread_read (GTlsThread *self,
cancellable, main_loop);
g_async_queue_push (self->queue, op);
g_main_context_wakeup (self->op_thread_context);
-
+GTLS_OP_DEBUG (op, "%s: timeout=%zd: starting read...", __FUNCTION__, timeout);
g_main_loop_run (main_loop);
*nread = op->count;
@@ -198,10 +200,15 @@ g_tls_thread_read (GTlsThread *self,
op->error = NULL;
}
+GTLS_OP_DEBUG (op, "%s: nread=%zd error=%s", __FUNCTION__, *nread, error && *error ? (*error)->message :
NULL);
+
+ result = op->result;
+
+ g_tls_thread_operation_free (op);
g_main_context_unref (main_context);
g_main_loop_unref (main_loop);
- return op->result;
+ return result;
}
typedef struct {
@@ -444,7 +451,6 @@ process_op (GAsyncQueue *queue,
* is different from op->main_loop, which runs on the original thread.
*/
g_main_loop_quit (main_loop);
- g_tls_thread_operation_free (op);
return G_SOURCE_REMOVE;
}
}
@@ -504,7 +510,6 @@ finished:
* This is different from main_loop, which is running the op thread.
*/
g_main_loop_quit (op->main_loop);
- g_tls_thread_operation_free (op);
return G_SOURCE_CONTINUE;
}
@@ -588,7 +593,7 @@ g_tls_thread_set_property (GObject *object,
static void
g_tls_thread_init (GTlsThread *self)
{
- self->queue = g_async_queue_new_full ((GDestroyNotify)g_tls_thread_operation_free);
+ self->queue = g_async_queue_new ();
self->op_thread_context = g_main_context_new ();
self->op_thread = g_thread_new ("[glib-networking] GTlsThreadBase TLS operations thread",
tls_op_thread,
@@ -599,13 +604,16 @@ static void
g_tls_thread_finalize (GObject *object)
{
GTlsThread *self = G_TLS_THREAD (object);
+ GTlsThreadOperation *op;
- g_async_queue_push (self->queue, g_tls_thread_shutdown_operation_new ());
+ op = g_tls_thread_shutdown_operation_new ();
+ g_async_queue_push (self->queue, op);
g_main_context_wakeup (self->op_thread_context);
g_clear_pointer (&self->op_thread, g_thread_join);
g_clear_pointer (&self->op_thread_context, g_main_context_unref);
g_clear_pointer (&self->queue, g_async_queue_unref);
+ g_tls_thread_operation_free (op);
g_clear_weak_pointer (&self->connection);
@@ -642,16 +650,33 @@ g_tls_thread_new (GTlsConnectionBase *tls)
return thread;
}
+// FIXME: Redundant
static void
GTLS_OP_DEBUG (GTlsThreadOperation *op,
const char *message,
...)
{
-
+ char *result = NULL;
+ GTlsConnection *connection = G_TLS_CONNECTION (op->connection);
+ int ret;
va_list args;
+
va_start (args, message);
- GTLS_DEBUG (op->connection, message, args);
+ ret = g_vasprintf (&result, message, args);
+ g_assert (ret > 0);
+
+ if (G_IS_TLS_CLIENT_CONNECTION (connection))
+ g_printf ("CLIENT %p: ", connection);
+ else if (G_IS_TLS_SERVER_CONNECTION (connection))
+ g_printf ("SERVER %p: ", connection);
+ else
+ g_assert_not_reached ();
+
+ g_printf ("%s\n", result);
+
+ fflush (stdout);
+ g_free (result);
va_end (args);
}
diff --git a/tls/gnutls/gtlsclientconnection-gnutls.c b/tls/gnutls/gtlsclientconnection-gnutls.c
index 384df22..7bb6216 100644
--- a/tls/gnutls/gtlsclientconnection-gnutls.c
+++ b/tls/gnutls/gtlsclientconnection-gnutls.c
@@ -448,6 +448,8 @@ g_tls_client_connection_gnutls_complete_handshake (GTlsConnectionBase *tls,
G_TLS_CONNECTION_BASE_CLASS (g_tls_client_connection_gnutls_parent_class)->
complete_handshake (tls, negotiated_protocol, error);
+ // FIXME: restore
+#if 0
resumed = gnutls_session_is_resumed (g_tls_connection_gnutls_get_session (G_TLS_CONNECTION_GNUTLS (tls)));
if (!resumed)
{
@@ -469,6 +471,7 @@ g_tls_client_connection_gnutls_complete_handshake (GTlsConnectionBase *tls,
gnutls->session_data);
}
}
+#endif
}
static void
diff --git a/tls/gnutls/gtlsconnection-gnutls.c b/tls/gnutls/gtlsconnection-gnutls.c
index ad1e949..4fe519a 100644
--- a/tls/gnutls/gtlsconnection-gnutls.c
+++ b/tls/gnutls/gtlsconnection-gnutls.c
@@ -1017,12 +1017,13 @@ g_tls_connection_gnutls_write (GTlsConnectionBase *tls,
GTlsConnectionGnutlsPrivate *priv = g_tls_connection_gnutls_get_instance_private (gnutls);
GTlsConnectionBaseStatus status;
gssize ret;
-
+GTLS_DEBUG (tls, "%s: writing buffer size=%zu", __FUNCTION__, size);
BEGIN_GNUTLS_IO (gnutls, G_IO_OUT, timeout, cancellable);
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);
+GTLS_DEBUG (tls, "%s: wrote %zd bytes", __FUNCTION__, ret);
return status;
}
diff --git a/tls/tests/connection.c b/tls/tests/connection.c
index 0db8cce..3d7a599 100644
--- a/tls/tests/connection.c
+++ b/tls/tests/connection.c
@@ -39,6 +39,9 @@
#include "openssl-include.h"
#endif
+//FIXME
+#include <glib/gstdio.h>
+
static const gchar *
tls_test_file_path (const char *name)
{
@@ -1644,6 +1647,8 @@ simul_async_read_complete (GObject *object,
nread = g_input_stream_read_finish (G_INPUT_STREAM (object),
result, &error);
g_assert_no_error (error);
+g_printf("%s: successfully read %zd bytes\n", __FUNCTION__, nread);
+fflush(stdout);
test->nread += nread;
g_assert_cmpint (test->nread, <=, TEST_DATA_LENGTH);
@@ -1676,10 +1681,14 @@ simul_async_write_complete (GObject *object,
nwrote = g_output_stream_write_finish (G_OUTPUT_STREAM (object),
result, &error);
g_assert_no_error (error);
+g_printf("%s: successfully wrote %zd bytes\n", __FUNCTION__, nwrote);
+fflush(stdout);
test->nwrote += nwrote;
if (test->nwrote < TEST_DATA_LENGTH)
{
+g_printf("test->nwrote=%zd < TEST_DATA_LENGTH %d, writing again...\n", test->nwrote, TEST_DATA_LENGTH);
+fflush(stdout);
g_output_stream_write_async (G_OUTPUT_STREAM (object),
&TEST_DATA[test->nwrote],
TEST_DATA_LENGTH - test->nwrote,
@@ -1709,6 +1718,9 @@ test_simultaneous_async (TestConnection *test,
memset (test->buf, 0, sizeof (test->buf));
test->nread = test->nwrote = 0;
+g_printf("%s: starting simul async read and async write\n", __FUNCTION__);
+fflush(stdout);
+
g_input_stream_read_async (g_io_stream_get_input_stream (test->client_connection),
test->buf, TEST_DATA_LENGTH / 2,
G_PRIORITY_DEFAULT, NULL,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]