[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: Mon, 12 Aug 2019 16:13:43 +0000 (UTC)
commit 0365a7590409a70ccaf07b4c7c6369296833166a
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Mon Aug 12 11:13:36 2019 -0500
progress
tls/base/gtlsconnection-base.c | 50 ------------------------------------------
tls/base/gtlsthread.c | 46 ++++++++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+), 50 deletions(-)
---
diff --git a/tls/base/gtlsconnection-base.c b/tls/base/gtlsconnection-base.c
index 4b89ab4..6855b2c 100644
--- a/tls/base/gtlsconnection-base.c
+++ b/tls/base/gtlsconnection-base.c
@@ -1851,40 +1851,6 @@ do_implicit_handshake (GTlsConnectionBase *tls,
}
}
-static gint64
-get_op_timeout (GTlsConnectionBase *tls,
- gint64 timeout)
-{
- GTlsConnectionBasePrivate *priv = g_tls_connection_base_get_instance_private (tls);
- GSocket *socket = NULL;
-
- /* Nonblocking? */
- if (timeout == 0)
- return 0;
-
- if (g_tls_connection_base_is_dtls (tls) && G_IS_SOCKET (priv->base_socket))
- socket = (GSocket *)priv->base_socket;
- else if (G_IS_SOCKET_CONNECTION (priv->base_io_stream))
- socket = g_socket_connection_get_socket ((GSocketConnection *)priv->base_io_stream);
-
- /* Never block for longer than the underlying socket timeout. */
- /* FIXME: close glib-networking#18 */
- if (socket)
- {
- gint64 socket_timeout = g_socket_get_timeout (socket);
- if (socket_timeout > 0)
- {
- if (timeout == -1)
- return socket_timeout;
-
- g_assert (timeout > 0);
- return MIN (timeout, socket_timeout);
- }
- }
-
- return timeout;
-}
-
gssize
g_tls_connection_base_read (GTlsConnectionBase *tls,
void *buffer,
@@ -1896,10 +1862,6 @@ 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);
-
- timeout = get_op_timeout (tls, timeout);
-GTLS_DEBUG (tls, "%s: adjusted timeout=%ld", __FUNCTION__, timeout);
do
{
@@ -1949,8 +1911,6 @@ g_tls_connection_base_read_message (GTlsConnectionBase *tls,
GTlsConnectionBaseStatus status;
gssize nread;
- timeout = get_op_timeout (tls, timeout);
-
do {
if (!claim_op (tls, G_TLS_CONNECTION_BASE_OP_READ,
timeout, cancellable, error))
@@ -2010,8 +1970,6 @@ g_tls_connection_base_receive_messages (GDatagramBased *datagram_based,
guint i;
GError *child_error = NULL;
- timeout = get_op_timeout (tls, timeout);
-
if (flags != G_SOCKET_MSG_NONE)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
@@ -2087,8 +2045,6 @@ g_tls_connection_base_write (GTlsConnectionBase *tls,
GTlsConnectionBaseStatus status;
gssize nwrote;
- timeout = get_op_timeout (tls, timeout);
-
do
{
if (!claim_op (tls, G_TLS_CONNECTION_BASE_OP_WRITE,
@@ -2123,8 +2079,6 @@ g_tls_connection_base_write_message (GTlsConnectionBase *tls,
GTlsConnectionBaseStatus status;
gssize nwrote;
- timeout = get_op_timeout (tls, timeout);
-
do {
if (!claim_op (tls, G_TLS_CONNECTION_BASE_OP_WRITE,
timeout, cancellable, error))
@@ -2160,8 +2114,6 @@ g_tls_connection_base_send_messages (GDatagramBased *datagram_based,
guint i;
GError *child_error = NULL;
- timeout = get_op_timeout (tls, timeout);
-
if (flags != G_SOCKET_MSG_NONE)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
@@ -2245,8 +2197,6 @@ g_tls_connection_base_close_internal (GIOStream *stream,
gboolean success = TRUE;
GError *close_error = NULL, *stream_error = NULL;
- timeout = get_op_timeout (tls, timeout);
-
/* This can be called from g_io_stream_close(), g_input_stream_close(),
* g_output_stream_close(), or g_tls_connection_close(). In all cases, we only
* do the close_fn() for writing. The difference is how we set the flags on
diff --git a/tls/base/gtlsthread.c b/tls/base/gtlsthread.c
index b177107..09d1641 100644
--- a/tls/base/gtlsthread.c
+++ b/tls/base/gtlsthread.c
@@ -412,6 +412,50 @@ dummy_callback (gpointer data)
return G_SOURCE_CONTINUE;
}
+static void
+adjust_op_timeout (GTlsThreadOperation *op)
+{
+ GSocket *socket = NULL;
+
+ /* Nonblocking? */
+ if (op->timeout == 0)
+ return;
+
+ if (g_tls_connection_base_is_dtls (op->connection))
+ {
+ GDatagramBased *base_socket = g_tls_connection_base_get_base_socket (op->connection);
+
+ if (G_IS_SOCKET (base_socket))
+ socket = (GSocket *)base_socket;
+ }
+ else
+ {
+ GIOStream *base_stream = g_tls_connection_base_get_base_iostream (op->connection);
+
+ if (G_IS_SOCKET_CONNECTION (base_stream))
+ socket = g_socket_connection_get_socket ((GSocketConnection *)base_stream);
+ }
+
+ /* We have to "massage" the timeout here because we are using only nonblocking
+ * I/O, so the underlying socket will never time out even if a timeout has
+ * been set. But if we are emulating a blocking operation, we need to make
+ * sure we don't block for longer than the underyling timeout.
+ */
+ if (socket)
+ {
+ gint64 socket_timeout = g_socket_get_timeout (socket);
+
+ if (socket_timeout > 0)
+ {
+ if (op->timeout == -1)
+ op->timeout = socket_timeout;
+
+ g_assert (op->timeout > 0);
+ op->timeout = MIN (op->timeout, socket_timeout);
+ }
+ }
+}
+
static gboolean
process_op (GAsyncQueue *queue,
GTlsThreadOperation *delayed_op,
@@ -480,6 +524,8 @@ GTLS_OP_DEBUG (op, "%s: New op %p from queue", __FUNCTION__, op);
g_main_loop_quit (main_loop);
return G_SOURCE_REMOVE;
}
+
+ adjust_op_timeout (op);
}
switch (op->type)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]