aboutsummaryrefslogtreecommitdiff
path: root/lib/multi.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2007-04-01 08:24:23 +0000
committerDaniel Stenberg <daniel@haxx.se>2007-04-01 08:24:23 +0000
commit6c6e4710b570eccdbae87fa9bd8df2f4940ac76d (patch)
tree09fbd6b8b0c96874d3ec123d467fee4b365f7355 /lib/multi.c
parent5e7164f87a7b65a4790b3b3e080664dabc8d50a4 (diff)
Robert Iakobashvili made curl_multi_remove_handle() a lot faster when many
easy handles are added to a multi handle, by avoiding the looping over all the handles to find which one to remove.
Diffstat (limited to 'lib/multi.c')
-rw-r--r--lib/multi.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/multi.c b/lib/multi.c
index ec9fd3309..54037b358 100644
--- a/lib/multi.c
+++ b/lib/multi.c
@@ -413,6 +413,9 @@ CURLMcode curl_multi_add_handle(CURLM *multi_handle,
easy->easy_handle = easy_handle;
multistate(easy, CURLM_STATE_INIT);
+ /* set the back pointer to one_easy to assist in removal */
+ easy->easy_handle->multi_pos = easy;
+
/* for multi interface connections, we share DNS cache automatically if the
easy handle's one is currently private. */
if (easy->easy_handle->dns.hostcache &&
@@ -516,13 +519,8 @@ CURLMcode curl_multi_remove_handle(CURLM *multi_handle,
if(!GOOD_EASY_HANDLE(curl_handle))
return CURLM_BAD_EASY_HANDLE;
- /* scan through the list and remove the 'curl_handle' */
- easy = multi->easy.next;
- while(easy != &multi->easy) {
- if(easy->easy_handle == (struct SessionHandle *)curl_handle)
- break;
- easy=easy->next;
- }
+ /* pick-up from the 'curl_handle' the kept position in the list */
+ easy = ((struct SessionHandle *)curl_handle)->multi_pos;
if(easy) {
bool premature = (bool)(easy->state != CURLM_STATE_COMPLETED);
@@ -626,6 +624,9 @@ CURLMcode curl_multi_remove_handle(CURLM *multi_handle,
easy->easy_handle->set.one_easy = NULL; /* detached */
+ /* Null the position in the controlling structure */
+ easy->easy_handle->multi_pos = NULL;
+
/* NOTE NOTE NOTE
We do not touch the easy handle here! */
if (easy->msg)