From c346c4c8f9503239ad3b5f2ba1cca9a317707e88 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 20 Aug 2013 14:48:08 +0200 Subject: multi_init: moved init code here from add_handle The closure_handle is "owned" by the multi handle and it is unconditional so the setting up of it should be in the Curl_multi_handle function rather than curl_multi_add_handle. --- lib/multi.c | 57 ++++++++++++++++++--------------------------------------- 1 file changed, 18 insertions(+), 39 deletions(-) diff --git a/lib/multi.c b/lib/multi.c index 32bd8bfd1..aa8eaf06b 100644 --- a/lib/multi.c +++ b/lib/multi.c @@ -307,6 +307,14 @@ struct Curl_multi *Curl_multi_handle(int hashsize, /* socket hash */ if(!multi->msglist) goto error; + /* allocate a new easy handle to use when closing cached connections */ + multi->closure_handle = curl_easy_init(); + if(!multi->closure_handle) + goto error; + + multi->closure_handle->multi = multi; + multi->closure_handle->state.conn_cache = multi->conn_cache; + multi->max_pipeline_length = 5; return (CURLM *) multi; @@ -318,6 +326,8 @@ struct Curl_multi *Curl_multi_handle(int hashsize, /* socket hash */ multi->hostcache = NULL; Curl_conncache_destroy(multi->conn_cache); multi->conn_cache = NULL; + Curl_close(multi->closure_handle); + multi->closure_handle = NULL; free(multi); return NULL; @@ -329,22 +339,12 @@ CURLM *curl_multi_init(void) CURL_CONNECTION_HASH_SIZE); } -/* - * Store a pointed to the multi handle within the easy handle's data struct. - */ -static void easy_addmulti(struct SessionHandle *data, - void *multi) -{ - data->multi = multi; -} - CURLMcode curl_multi_add_handle(CURLM *multi_handle, CURL *easy_handle) { struct curl_llist *timeoutlist; struct Curl_multi *multi = (struct Curl_multi *)multi_handle; struct SessionHandle *data = (struct SessionHandle *)easy_handle; - struct SessionHandle *new_closure = NULL; /* First, make some basic checks that the CURLM handle is a good handle */ if(!GOOD_MULTI_HANDLE(multi)) @@ -365,31 +365,12 @@ CURLMcode curl_multi_add_handle(CURLM *multi_handle, if(!timeoutlist) return CURLM_OUT_OF_MEMORY; - /* In case multi handle has no closure_handle yet, allocate - a new easy handle to use when closing cached connections */ - if(!multi->closure_handle) { - new_closure = (struct SessionHandle *)curl_easy_init(); - if(!new_closure) { - free(data); - Curl_llist_destroy(timeoutlist, NULL); - return CURLM_OUT_OF_MEMORY; - } - } - /* - ** No failure allowed in this function beyond this point. And - ** no modification of easy nor multi handle allowed before this - ** except for potential multi's connection cache growing which - ** won't be undone in this function no matter what. - */ - - /* In case a new closure handle has been initialized above, it - is associated now with the multi handle which lacked one. */ - if(new_closure) { - multi->closure_handle = new_closure; - easy_addmulti(multi->closure_handle, multi_handle); - multi->closure_handle->state.conn_cache = multi->conn_cache; - } + * No failure allowed in this function beyond this point. And no + * modification of easy nor multi handle allowed before this except for + * potential multi's connection cache growing which won't be undone in this + * function no matter what. + */ /* Make easy handle use timeout list initialized above */ data->state.timeoutlist = timeoutlist; @@ -440,7 +421,7 @@ CURLMcode curl_multi_add_handle(CURLM *multi_handle, } /* make the SessionHandle refer back to this multi handle */ - easy_addmulti(easy_handle, multi_handle); + data->multi = multi_handle; /* Set the timeout for this handle to expire really soon so that it will be taken care of even when this handle is added in the midst of operation @@ -581,8 +562,7 @@ CURLMcode curl_multi_remove_handle(CURLM *multi_handle, data->easy_conn = NULL; } - easy_addmulti(data, NULL); /* clear the association to this multi - handle */ + data->multi = NULL; /* clear the association to this multi handle */ { /* make sure there's no pending message in the queue sent from this easy @@ -1836,8 +1816,7 @@ CURLMcode curl_multi_cleanup(CURLM *multi_handle) /* Clear the pointer to the connection cache */ data->state.conn_cache = NULL; - - easy_addmulti(data, NULL); /* clear the association */ + data->multi = NULL; /* clear the association */ data = nextdata; } -- cgit v1.2.3