[glib-networking/wip/pwithnall/dtls: 11/12] fixup! gnutls: Internally support per-operation timeouts
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib-networking/wip/pwithnall/dtls: 11/12] fixup! gnutls: Internally support per-operation timeouts
- Date: Mon, 18 Jan 2016 18:09:39 +0000 (UTC)
commit 979fd1ffe7778573f23a052ff8edc28255ca72f1
Author: Philip Withnall <philip withnall collabora co uk>
Date: Mon Jan 18 17:52:37 2016 +0000
fixup! gnutls: Internally support per-operation timeouts
tls/tests/dtls-connection.c | 64 +++++++++++++++++++++++++++++++++++++++----
1 files changed, 58 insertions(+), 6 deletions(-)
---
diff --git a/tls/tests/dtls-connection.c b/tls/tests/dtls-connection.c
index 5c4e1b9..a92db58 100644
--- a/tls/tests/dtls-connection.c
+++ b/tls/tests/dtls-connection.c
@@ -78,6 +78,11 @@ typedef struct {
gboolean server_should_close;
gboolean server_running;
+ /* Timeout (in microseconds) applied to each read and write operation.
+ * 0 means no blocking; -1 means blocking indefinitely. */
+ gint64 server_timeout;
+ gint64 client_timeout;
+
char buf[128];
gssize nread, nwrote;
} TestConnection;
@@ -229,11 +234,15 @@ on_rehandshake_finish (GObject *object,
g_clear_error (&test->server_error);
n_sent = g_datagram_based_send_messages (test->server_connection,
&message, 1,
- G_SOCKET_MSG_NONE, 0, NULL,
+ G_SOCKET_MSG_NONE,
+ test->server_timeout, NULL,
&test->server_error);
g_main_context_iteration (NULL, FALSE);
}
- while (g_error_matches (test->server_error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK));
+ while ((test->server_timeout == 0 &&
+ g_error_matches (test->server_error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) ||
+ (test->server_timeout > 0 &&
+ g_error_matches (test->server_error, G_IO_ERROR, G_IO_ERROR_TIMED_OUT)));
if (!test->server_error)
{
@@ -335,11 +344,15 @@ on_incoming_connection (GSocket *socket,
g_clear_error (&test->server_error);
n_sent = g_datagram_based_send_messages (test->server_connection,
&message, 1,
- G_SOCKET_MSG_NONE, 0, NULL,
+ G_SOCKET_MSG_NONE,
+ test->server_timeout, NULL,
&test->server_error);
g_main_context_iteration (NULL, FALSE);
}
- while (g_error_matches (test->server_error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK));
+ while ((test->server_timeout == 0 &&
+ g_error_matches (test->server_error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) ||
+ (test->server_timeout > 0 &&
+ g_error_matches (test->server_error, G_IO_ERROR, G_IO_ERROR_TIMED_OUT)));
if (!test->server_error)
{
@@ -416,11 +429,15 @@ read_test_data_async (TestConnection *test)
g_clear_error (&test->read_error);
n_read = g_datagram_based_receive_messages (test->client_connection,
&message, 1,
- G_SOCKET_MSG_NONE, 0,
+ G_SOCKET_MSG_NONE,
+ test->client_timeout,
NULL, &test->read_error);
g_main_context_iteration (NULL, FALSE);
}
- while (g_error_matches (test->read_error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK));
+ while ((test->client_timeout == 0 &&
+ g_error_matches (test->read_error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) ||
+ (test->client_timeout > 0 &&
+ g_error_matches (test->read_error, G_IO_ERROR, G_IO_ERROR_TIMED_OUT)));
if (!test->read_error)
{
@@ -446,6 +463,38 @@ test_basic_connection (TestConnection *test,
GDatagramBased *connection;
GError *error = NULL;
+ test->server_timeout = 0; /* no blocking */
+ test->client_timeout = 0; /* no blocking */
+
+ connection = start_async_server_and_connect_to_it (test, G_TLS_AUTHENTICATION_NONE, TRUE);
+ test->client_connection = g_dtls_client_connection_new (connection, test->identity, &error);
+ g_debug ("%s: Client connection %p on socket %p", G_STRFUNC, test->client_connection, connection);
+ g_assert_no_error (error);
+ g_object_unref (connection);
+
+ /* No validation at all in this test */
+ g_dtls_client_connection_set_validation_flags (G_DTLS_CLIENT_CONNECTION (test->client_connection),
+ 0);
+
+ read_test_data_async (test);
+ while (!test->loop_finished)
+ g_main_context_iteration (test->context, TRUE);
+
+ g_assert_no_error (test->server_error);
+ g_assert_no_error (test->read_error);
+}
+
+/* Test that per-operation timeouts for reads and writes work. */
+static void
+test_per_operation_timeouts (TestConnection *test,
+ gconstpointer data)
+{
+ GDatagramBased *connection;
+ GError *error = NULL;
+
+ test->server_timeout = 10 * 1000; /* 10ms */
+ test->client_timeout = 10 * 1000; /* 10ms */
+
connection = start_async_server_and_connect_to_it (test, G_TLS_AUTHENTICATION_NONE, TRUE);
test->client_connection = g_dtls_client_connection_new (connection, test->identity, &error);
g_debug ("%s: Client connection %p on socket %p", G_STRFUNC, test->client_connection, connection);
@@ -498,6 +547,9 @@ main (int argc,
g_test_add ("/dtls/connection/basic", TestConnection, NULL,
setup_connection, test_basic_connection, teardown_connection);
+ g_test_add ("/dtls/connection/per-operation-timeouts", TestConnection, NULL,
+ setup_connection, test_per_operation_timeouts,
+ teardown_connection);
ret = g_test_run();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]