From 83735da1c001c946df6c14bd7659a615739e8cb8 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos Date: Fri, 16 Oct 2020 14:26:05 +0200 Subject: session: add io priority parameter to soup_session_send_async() And use it for the all the IO async operations where possible. --- libsoup/soup-message-io.c | 19 +++++++++++++++++-- libsoup/soup-message-private.h | 1 + libsoup/soup-request-http.c | 4 +++- libsoup/soup-session.c | 10 ++++++++-- libsoup/soup-session.h | 1 + tests/auth-test.c | 17 +++++++++-------- tests/connection-test.c | 6 +++--- tests/context-test.c | 2 +- tests/cookies-test.c | 3 ++- tests/misc-test.c | 12 ++++++------ tests/pull-api-test.c | 2 +- tests/session-test.c | 6 +++--- tests/test-utils.c | 3 ++- 13 files changed, 57 insertions(+), 29 deletions(-) diff --git a/libsoup/soup-message-io.c b/libsoup/soup-message-io.c index efa84ef6..feb88672 100644 --- a/libsoup/soup-message-io.c +++ b/libsoup/soup-message-io.c @@ -54,6 +54,15 @@ soup_client_message_io_data_free (SoupClientMessageIOData *io) g_slice_free (SoupClientMessageIOData, io); } +static int +soup_client_message_io_data_get_priority (SoupClientMessageIOData *io) +{ + if (!io->item->task) + return G_PRIORITY_DEFAULT; + + return g_task_get_priority (io->item->task); +} + void soup_message_io_finished (SoupMessage *msg) { @@ -409,7 +418,7 @@ io_write (SoupMessage *msg, gboolean blocking, g_output_stream_splice_async (io->body_ostream, msg->request_body_stream, G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE, - G_PRIORITY_DEFAULT, + soup_client_message_io_data_get_priority (client_io), cancellable, (GAsyncReadyCallback)request_body_stream_wrote_cb, g_object_ref (msg)); @@ -430,7 +439,8 @@ io_write (SoupMessage *msg, gboolean blocking, io->async_wait = g_cancellable_new (); g_main_context_push_thread_default (io->async_context); g_output_stream_close_async (io->body_ostream, - G_PRIORITY_DEFAULT, cancellable, + soup_client_message_io_data_get_priority (client_io), + cancellable, closed_async, g_object_ref (msg)); g_main_context_pop_thread_default (io->async_context); } @@ -837,6 +847,8 @@ soup_message_io_run (SoupMessage *msg, io->io_source = soup_message_io_data_get_source (io, G_OBJECT (msg), NULL, (SoupMessageIOSourceFunc)io_run_ready, NULL); + g_source_set_priority (io->io_source, + soup_client_message_io_data_get_priority (client_io)); g_source_attach (io->io_source, io->async_context); } else { if (soup_message_get_io_data (msg) == client_io) @@ -910,6 +922,7 @@ io_run_until_read_async (SoupMessage *msg, io->io_source = soup_message_io_data_get_source (io, G_OBJECT (msg), NULL, (SoupMessageIOSourceFunc)io_run_until_read_ready, task); + g_source_set_priority (io->io_source, g_task_get_priority (task)); g_source_attach (io->io_source, io->async_context); return; } @@ -923,6 +936,7 @@ io_run_until_read_async (SoupMessage *msg, void soup_message_io_run_until_read_async (SoupMessage *msg, + int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) @@ -930,6 +944,7 @@ soup_message_io_run_until_read_async (SoupMessage *msg, GTask *task; task = g_task_new (msg, cancellable, callback, user_data); + g_task_set_priority (task, io_priority); io_run_until_read_async (msg, task); } diff --git a/libsoup/soup-message-private.h b/libsoup/soup-message-private.h index 0ce07e8f..21b3a07f 100644 --- a/libsoup/soup-message-private.h +++ b/libsoup/soup-message-private.h @@ -100,6 +100,7 @@ gboolean soup_message_io_run_until_read (SoupMessage *msg, GCancellable *cancellable, GError **error); void soup_message_io_run_until_read_async (SoupMessage *msg, + int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); diff --git a/libsoup/soup-request-http.c b/libsoup/soup-request-http.c index d4a4cd87..5dbfe0e9 100644 --- a/libsoup/soup-request-http.c +++ b/libsoup/soup-request-http.c @@ -143,7 +143,9 @@ soup_request_http_send_async (SoupRequest *request, GTask *task; task = g_task_new (request, cancellable, callback, user_data); - soup_session_send_async (session, priv->msg, cancellable, + soup_session_send_async (session, priv->msg, + G_PRIORITY_DEFAULT, + cancellable, http_input_stream_ready_cb, task); } diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c index 407ac314..55541963 100644 --- a/libsoup/soup-session.c +++ b/libsoup/soup-session.c @@ -3163,7 +3163,7 @@ send_async_maybe_complete (SoupMessageQueueItem *item, */ g_output_stream_splice_async (ostream, stream, G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, - G_PRIORITY_DEFAULT, + g_task_get_priority (item->task), item->cancellable, send_async_spliced, item); return; @@ -3207,6 +3207,7 @@ async_send_request_running (SoupSession *session, SoupMessageQueueItem *item) if (item->task) { item->io_started = TRUE; soup_message_io_run_until_read_async (item->msg, + g_task_get_priority (item->task), item->cancellable, (GAsyncReadyCallback)run_until_read_done, item); @@ -3380,7 +3381,9 @@ async_respond_from_cache (SoupSession *session, data->item = item; soup_message_queue_item_ref (item); soup_message_disable_feature (conditional_msg, SOUP_TYPE_CACHE); - soup_session_send_async (session, conditional_msg, item->cancellable, + soup_session_send_async (session, conditional_msg, + g_task_get_priority (item->task), + item->cancellable, (GAsyncReadyCallback)conditional_get_ready_cb, data); @@ -3399,6 +3402,7 @@ cancel_cancellable (G_GNUC_UNUSED GCancellable *cancellable, GCancellable *chain * soup_session_send_async: * @session: a #SoupSession * @msg: a #SoupMessage + * @io_priority: the I/O priority of the request * @cancellable: a #GCancellable * @callback: the callback to invoke * @user_data: data for @callback @@ -3416,6 +3420,7 @@ cancel_cancellable (G_GNUC_UNUSED GCancellable *cancellable, GCancellable *chain void soup_session_send_async (SoupSession *session, SoupMessage *msg, + int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) @@ -3438,6 +3443,7 @@ soup_session_send_async (SoupSession *session, } item->task = g_task_new (session, item->cancellable, callback, user_data); + g_task_set_priority (item->task, io_priority); g_task_set_task_data (item->task, item, (GDestroyNotify) soup_message_queue_item_unref); /* Do not check for cancellations as we do not want to diff --git a/libsoup/soup-session.h b/libsoup/soup-session.h index a4bcfac7..c066212c 100644 --- a/libsoup/soup-session.h +++ b/libsoup/soup-session.h @@ -58,6 +58,7 @@ void soup_session_abort (SoupSession *session); SOUP_AVAILABLE_IN_2_42 void soup_session_send_async (SoupSession *session, SoupMessage *msg, + int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); diff --git a/tests/auth-test.c b/tests/auth-test.c index 1f3ba064..0bacbb80 100644 --- a/tests/auth-test.c +++ b/tests/auth-test.c @@ -311,7 +311,7 @@ do_pipelined_auth_test (void) g_signal_connect (msg, "finished", G_CALLBACK (bug271540_finished), &i); - soup_session_send_async (session, msg, NULL, NULL, NULL); + soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, NULL, NULL, NULL); g_object_unref (msg); } g_free (uri); @@ -577,7 +577,7 @@ do_async_auth_good_password_test (void) remaining++; g_signal_connect (msg1, "finished", G_CALLBACK (async_finished), &remaining); - soup_session_send_async (session, msg1, NULL, NULL, NULL); + soup_session_send_async (session, msg1, G_PRIORITY_DEFAULT, NULL, NULL, NULL); g_main_loop_run (loop); g_signal_handler_disconnect (session, auth_id); @@ -603,7 +603,7 @@ do_async_auth_good_password_test (void) remaining++; g_signal_connect (msg3, "finished", G_CALLBACK (async_finished), &remaining); - soup_session_send_async (session, msg3, NULL, NULL, NULL); + soup_session_send_async (session, msg3, G_PRIORITY_DEFAULT, NULL, NULL, NULL); g_main_loop_run (loop); g_signal_handler_disconnect (session, auth_id); @@ -667,7 +667,7 @@ do_async_auth_bad_password_test (void) remaining++; g_signal_connect (msg, "finished", G_CALLBACK (async_finished), &remaining); - soup_session_send_async (session, msg, NULL, NULL, NULL); + soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, NULL, NULL, NULL); g_main_loop_run (loop); g_signal_handler_disconnect (session, auth_id); soup_auth_authenticate (auth, "user1", "wrong"); @@ -722,7 +722,7 @@ do_async_auth_no_password_test (void) remaining++; g_signal_connect (msg, "finished", G_CALLBACK (async_finished), &remaining); - soup_session_send_async (session, msg, NULL, NULL, NULL); + soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, NULL, NULL, NULL); g_main_loop_run (loop); g_signal_handler_disconnect (session, auth_id); soup_session_unpause_message (session, msg); @@ -739,7 +739,7 @@ do_async_auth_no_password_test (void) remaining++; g_signal_connect (msg, "finished", G_CALLBACK (async_finished), &remaining); - soup_session_send_async (session, msg, NULL, NULL, NULL); + soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, NULL, NULL, NULL); g_main_loop_run (loop); soup_session_unpause_message (session, msg); @@ -1427,7 +1427,7 @@ do_async_message_do_not_use_auth_cache_test (void) soup_message_set_flags (msg, flags | SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE); g_signal_connect (msg, "finished", G_CALLBACK (async_no_auth_cache_finished), NULL); - soup_session_send_async (session, msg, NULL, NULL, NULL); + soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, NULL, NULL, NULL); g_main_loop_run (loop); soup_test_assert_message_status (msg, SOUP_STATUS_UNAUTHORIZED); @@ -1569,7 +1569,8 @@ do_cancel_after_retry_test (void) uri = g_strconcat (base_uri, "Digest/realm1/", NULL); msg = soup_message_new ("GET", uri); - soup_session_send_async (session, msg, cancellable, (GAsyncReadyCallback)request_send_cb, loop); + soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, cancellable, + (GAsyncReadyCallback)request_send_cb, loop); g_main_loop_run (loop); g_object_unref (msg); diff --git a/tests/connection-test.c b/tests/connection-test.c index e37f66ec..92d02450 100644 --- a/tests/connection-test.c +++ b/tests/connection-test.c @@ -570,7 +570,7 @@ do_max_conns_test_for_session (SoupSession *session) msgs[i] = soup_message_new_from_uri ("GET", base_uri); g_signal_connect (msgs[i], "finished", G_CALLBACK (max_conns_message_complete), NULL); - soup_session_send_async (session, msgs[i], NULL, NULL, NULL); + soup_session_send_async (session, msgs[i], G_PRIORITY_DEFAULT, NULL, NULL, NULL); } g_main_loop_run (max_conns_loop); @@ -589,7 +589,7 @@ do_max_conns_test_for_session (SoupSession *session) soup_message_set_flags (msgs[i], flags | SOUP_MESSAGE_IGNORE_CONNECTION_LIMITS); g_signal_connect (msgs[i], "finished", G_CALLBACK (max_conns_message_complete), NULL); - soup_session_send_async (session, msgs[i], NULL, NULL, NULL); + soup_session_send_async (session, msgs[i], G_PRIORITY_DEFAULT, NULL, NULL, NULL); g_main_loop_run (max_conns_loop); g_assert_cmpint (msgs_done, ==, MAX_CONNS + 1); @@ -696,7 +696,7 @@ do_non_persistent_test_for_session (SoupSession *session) soup_message_headers_append (msg->request_headers, "Connection", "close"); g_signal_connect (msg, "finished", G_CALLBACK (np_request_finished), loop); - soup_session_send_async (session, msg, NULL, NULL, NULL); + soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, NULL, NULL, NULL); g_main_loop_run (loop); g_main_loop_unref (loop); diff --git a/tests/context-test.c b/tests/context-test.c index e8c55dc8..64367432 100644 --- a/tests/context-test.c +++ b/tests/context-test.c @@ -163,7 +163,7 @@ test1_thread (gpointer user_data) msg = soup_message_new ("GET", uri); loop = g_main_loop_new (async_context, FALSE); g_signal_connect (msg, "finished", G_CALLBACK (test1_finished), loop); - soup_session_send_async (session, msg, NULL, NULL, NULL); + soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, NULL, NULL, NULL); g_main_loop_run (loop); /* We need one more iteration, because SoupMessage::finished is emitted * right before the message is unqueued. diff --git a/tests/cookies-test.c b/tests/cookies-test.c index 163f4f42..3986191d 100644 --- a/tests/cookies-test.c +++ b/tests/cookies-test.c @@ -410,7 +410,8 @@ do_remove_feature_test (void) soup_message_set_first_party (msg, first_party_uri); loop = g_main_loop_new (NULL, TRUE); - soup_session_send_async (session, msg, NULL, (GAsyncReadyCallback)send_callback, loop); + soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, NULL, + (GAsyncReadyCallback)send_callback, loop); soup_session_remove_feature_by_type (session, SOUP_TYPE_COOKIE_JAR); g_main_loop_run(loop); diff --git a/tests/misc-test.c b/tests/misc-test.c index 844d9cdd..042e63ba 100644 --- a/tests/misc-test.c +++ b/tests/misc-test.c @@ -227,8 +227,8 @@ do_callback_unref_test (void) g_object_add_weak_pointer (G_OBJECT (two), (gpointer *)&two); soup_uri_free (bad_uri); - soup_session_send_async (session, one, NULL, NULL, NULL); - soup_session_send_async (session, two, NULL, NULL, NULL); + soup_session_send_async (session, one, G_PRIORITY_DEFAULT, NULL, NULL, NULL); + soup_session_send_async (session, two, G_PRIORITY_DEFAULT, NULL, NULL, NULL); g_object_unref (one); g_object_unref (two); @@ -476,7 +476,7 @@ do_early_abort_test (void) loop = g_main_loop_new (context, TRUE); g_signal_connect (msg, "finished", G_CALLBACK (ea_msg_completed_one), loop); - soup_session_send_async (session, msg, NULL, NULL, NULL); + soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, NULL, NULL, NULL); g_object_unref (msg); g_main_context_iteration (context, FALSE); @@ -714,7 +714,7 @@ do_cancel_while_reading_test_for_session (SoupSession *session) g_signal_connect (msg, "finished", G_CALLBACK (set_done), &done); - soup_session_send_async (session, msg, NULL, NULL, NULL); + soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, NULL, NULL, NULL); while (!done) g_main_context_iteration (NULL, TRUE); /* We need one more iteration, because SoupMessage::finished is emitted @@ -871,7 +871,7 @@ do_pause_abort_test (void) session = soup_test_session_new (SOUP_TYPE_SESSION, NULL); msg = soup_message_new_from_uri ("GET", base_uri); - soup_session_send_async (session, msg, NULL, NULL, NULL); + soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, NULL, NULL, NULL); soup_session_pause_message (session, msg); g_object_add_weak_pointer (G_OBJECT (msg), &ptr); @@ -940,7 +940,7 @@ do_pause_cancel_test (void) G_CALLBACK (pause_cancel_got_headers), session); g_signal_connect (msg, "finished", G_CALLBACK (pause_cancel_finished), &finished); - soup_session_send_async (session, msg, NULL, NULL, NULL); + soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, NULL, NULL, NULL); g_main_loop_run (pause_cancel_loop); g_assert_false (finished); diff --git a/tests/pull-api-test.c b/tests/pull-api-test.c index 36d44a5e..edb4726d 100644 --- a/tests/pull-api-test.c +++ b/tests/pull-api-test.c @@ -106,7 +106,7 @@ do_fully_async_test (SoupSession *session, /* Send the request */ g_signal_connect (msg, "finished", G_CALLBACK (fully_async_finished), &ad); - soup_session_send_async (session, msg, NULL, NULL, NULL); + soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, NULL, NULL, NULL); /* In a real program, we'd probably just return at this point. * Eventually the caller would return all the way to the main diff --git a/tests/session-test.c b/tests/session-test.c index be85d669..1e8d2b14 100644 --- a/tests/session-test.c +++ b/tests/session-test.c @@ -79,7 +79,7 @@ do_test_for_session (SoupSession *session, SoupURI *uri, server_processed_message = timeout = finished = FALSE; g_signal_connect (msg, "finished", G_CALLBACK (finished_cb), &finished); - soup_session_send_async (session, msg, NULL, NULL, NULL); + soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, NULL, NULL, NULL); g_object_unref (msg); while (!timeout) g_usleep (100); @@ -128,7 +128,7 @@ do_test_for_session (SoupSession *session, SoupURI *uri, finished = FALSE; g_signal_connect (msg, "finished", G_CALLBACK (finished_cb), &finished); - soup_session_send_async (session, msg, NULL, NULL, NULL); + soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, NULL, NULL, NULL); g_signal_connect (msg, "wrote-headers", G_CALLBACK (cancel_message_cb), session); @@ -215,7 +215,7 @@ do_priority_tests (gconstpointer data) soup_message_set_priority (msg, priorities[i]); g_signal_connect (msg, "finished", G_CALLBACK (priority_test_finished_cb), &finished_count); - soup_session_send_async (session, msg, NULL, NULL, NULL); + soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, NULL, NULL, NULL); g_object_unref (msg); } diff --git a/tests/test-utils.c b/tests/test-utils.c index 2dacdb3d..eefefec7 100644 --- a/tests/test-utils.c +++ b/tests/test-utils.c @@ -344,7 +344,8 @@ soup_test_session_async_send (SoupSession *session, signal_id = g_signal_connect (msg, "finished", G_CALLBACK (on_message_finished), &message_finished); - soup_session_send_async (session, msg, NULL, (GAsyncReadyCallback)send_async_ready_cb, &body); + soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, NULL, + (GAsyncReadyCallback)send_async_ready_cb, &body); while (!message_finished) g_main_context_iteration (async_context, TRUE); -- cgit v1.2.1