From 93257caa914d8df3d65a73e9ce19f2753e2e3240 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 24 Oct 2023 16:10:11 +0200 Subject: [PATCH] connectivity: use GSource pointer for curl_timer instead of numeric source-id I think GSource* is preferable, because it's more type-safe than the guint numbers. Also, g_source_remove() only works with g_main_context_default(), while g_source_detach() of a GSource pointer works with any GMainContext (so it's more general, even if we in this case only have sources attached to g_main_context_default()). Handling GSource* pointers is possibly also faster, since it saves one extra g_main_context_find_source_by_id() -- on the other hand, tracking the pointer costs 8 bytes while tracking the guint only costs 4 bytes. Whether it's faster is unproven, but possibly it is. In any case it's not an argument against using pointers. Anyway. Update another usage of source-ids to use GSource pointers. This is also the pattern that "checkpatch.pl" suggests. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1774 --- src/core/nm-connectivity.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/core/nm-connectivity.c b/src/core/nm-connectivity.c index d8b0004c38..76223cf121 100644 --- a/src/core/nm-connectivity.c +++ b/src/core/nm-connectivity.c @@ -79,9 +79,9 @@ struct _NMConnectivityCheckHandle { struct curl_slist *request_headers; struct curl_slist *hosts; - gsize response_good_cnt; + GSource *curl_timer; - guint curl_timer; + gsize response_good_cnt; } concheck; #endif @@ -241,7 +241,7 @@ cb_data_complete(NMConnectivityCheckHandle *cb_data, curl_slist_free_all(cb_data->concheck.request_headers); curl_slist_free_all(cb_data->concheck.hosts); } - nm_clear_g_source(&cb_data->concheck.curl_timer); + nm_clear_g_source_inst(&cb_data->concheck.curl_timer); nm_clear_g_cancellable(&cb_data->concheck.resolve_cancellable); #endif @@ -406,10 +406,10 @@ _con_curl_timeout_cb(gpointer user_data) { NMConnectivityCheckHandle *cb_data = user_data; - cb_data->concheck.curl_timer = 0; + nm_clear_g_source_inst(&cb_data->concheck.curl_timer); _con_curl_check_connectivity(cb_data->concheck.curl_mhandle, CURL_SOCKET_TIMEOUT, 0); _complete_queued(cb_data->self); - return G_SOURCE_REMOVE; + return G_SOURCE_CONTINUE; } static int @@ -417,9 +417,11 @@ multi_timer_cb(CURLM *multi, long timeout_msec, void *userdata) { NMConnectivityCheckHandle *cb_data = userdata; - nm_clear_g_source(&cb_data->concheck.curl_timer); - if (timeout_msec != -1) - cb_data->concheck.curl_timer = g_timeout_add(timeout_msec, _con_curl_timeout_cb, cb_data); + nm_clear_g_source_inst(&cb_data->concheck.curl_timer); + if (timeout_msec != -1) { + cb_data->concheck.curl_timer = + nm_g_timeout_add_source(timeout_msec, _con_curl_timeout_cb, cb_data); + } return 0; }