summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2023-03-14 12:20:24 +0100
committerDaniel Stenberg <daniel@haxx.se>2023-03-15 10:37:48 +0100
commita208be371019a5bcbae9bc6c8ef302782ee43e8d (patch)
treee067ee52dc3c0eea1b48aff92419b78dc6b65d63
parent18a45a51ba1fec2bd3da23233a55df5c087396d7 (diff)
downloadcurl-a208be371019a5bcbae9bc6c8ef302782ee43e8d.tar.gz
multi: turn link/unlinking easy handles into dedicated functions
-rw-r--r--lib/multi.c62
1 files changed, 38 insertions, 24 deletions
diff --git a/lib/multi.c b/lib/multi.c
index b466a49b7..731b2598f 100644
--- a/lib/multi.c
+++ b/lib/multi.c
@@ -456,6 +456,42 @@ struct Curl_multi *curl_multi_init(void)
CURL_DNS_HASH_SIZE);
}
+static void link_easy(struct Curl_multi *multi,
+ struct Curl_easy *data)
+{
+ /* We add the new easy entry last in the list. */
+ data->next = NULL; /* end of the line */
+ if(multi->easyp) {
+ struct Curl_easy *last = multi->easylp;
+ last->next = data;
+ data->prev = last;
+ multi->easylp = data; /* the new last node */
+ }
+ else {
+ /* first node, make prev NULL! */
+ data->prev = NULL;
+ multi->easylp = multi->easyp = data; /* both first and last */
+ }
+}
+
+/* unlink the given easy handle from the linked list of easy handles */
+static void unlink_easy(struct Curl_multi *multi,
+ struct Curl_easy *data)
+{
+ /* make the previous node point to our next */
+ if(data->prev)
+ data->prev->next = data->next;
+ else
+ multi->easyp = data->next; /* point to first node */
+
+ /* make our next point to our previous node */
+ if(data->next)
+ data->next->prev = data->prev;
+ else
+ multi->easylp = data->prev; /* point to last node */
+}
+
+
CURLMcode curl_multi_add_handle(struct Curl_multi *multi,
struct Curl_easy *data)
{
@@ -551,19 +587,7 @@ CURLMcode curl_multi_add_handle(struct Curl_multi *multi,
data->psl = &multi->psl;
#endif
- /* We add the new entry last in the list. */
- data->next = NULL; /* end of the line */
- if(multi->easyp) {
- struct Curl_easy *last = multi->easylp;
- last->next = data;
- data->prev = last;
- multi->easylp = data; /* the new last node */
- }
- else {
- /* first node, make prev NULL! */
- data->prev = NULL;
- multi->easylp = multi->easyp = data; /* both first and last */
- }
+ link_easy(multi, data);
/* increase the node-counter */
multi->num_easy++;
@@ -910,17 +934,7 @@ CURLMcode curl_multi_remove_handle(struct Curl_multi *multi,
}
}
- /* make the previous node point to our next */
- if(data->prev)
- data->prev->next = data->next;
- else
- multi->easyp = data->next; /* point to first node */
-
- /* make our next point to our previous node */
- if(data->next)
- data->next->prev = data->prev;
- else
- multi->easylp = data->prev; /* point to last node */
+ unlink_easy(multi, data);
/* NOTE NOTE NOTE
We do not touch the easy handle here! */