[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 23:33:12 +0000 (UTC)
commit 792f57758c5fde7ceb3208a6919509dbfdd3819b
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Sun Aug 11 17:45:27 2019 -0500
progress!
tls/base/gtlsconnection-base.c | 49 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
---
diff --git a/tls/base/gtlsconnection-base.c b/tls/base/gtlsconnection-base.c
index e4712ba..4b89ab4 100644
--- a/tls/base/gtlsconnection-base.c
+++ b/tls/base/gtlsconnection-base.c
@@ -1851,6 +1851,40 @@ 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,
@@ -1864,6 +1898,9 @@ g_tls_connection_base_read (GTlsConnectionBase *tls,
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
{
if (!claim_op (tls, G_TLS_CONNECTION_BASE_OP_READ,
@@ -1912,6 +1949,8 @@ 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))
@@ -1971,6 +2010,8 @@ 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,
@@ -2046,6 +2087,8 @@ 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,
@@ -2080,6 +2123,8 @@ 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))
@@ -2115,6 +2160,8 @@ 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,
@@ -2198,6 +2245,8 @@ 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]