mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-14 05:10:35 +01:00
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
This commit is contained in:
parent
8d2e510065
commit
93257caa91
1 changed files with 10 additions and 8 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue