curl_multi_remove_handle: remove dead code
Coverify CID 1157776. Removed a superfluous if() that always evaluated true (and an else clause that never ran), and then re-indented the function accordingly.
This commit is contained in:
225
lib/multi.c
225
lib/multi.c
@@ -487,6 +487,9 @@ CURLMcode curl_multi_remove_handle(CURLM *multi_handle,
|
|||||||
struct Curl_multi *multi=(struct Curl_multi *)multi_handle;
|
struct Curl_multi *multi=(struct Curl_multi *)multi_handle;
|
||||||
struct SessionHandle *easy = curl_handle;
|
struct SessionHandle *easy = curl_handle;
|
||||||
struct SessionHandle *data = easy;
|
struct SessionHandle *data = easy;
|
||||||
|
bool premature;
|
||||||
|
bool easy_owns_conn;
|
||||||
|
struct curl_llist_element *e;
|
||||||
|
|
||||||
/* First, make some basic checks that the CURLM handle is a good handle */
|
/* First, make some basic checks that the CURLM handle is a good handle */
|
||||||
if(!GOOD_MULTI_HANDLE(multi))
|
if(!GOOD_MULTI_HANDLE(multi))
|
||||||
@@ -500,126 +503,118 @@ CURLMcode curl_multi_remove_handle(CURLM *multi_handle,
|
|||||||
if(!data->multi)
|
if(!data->multi)
|
||||||
return CURLM_OK; /* it is already removed so let's say it is fine! */
|
return CURLM_OK; /* it is already removed so let's say it is fine! */
|
||||||
|
|
||||||
if(easy) {
|
|
||||||
bool premature = (data->mstate < CURLM_STATE_COMPLETED) ? TRUE : FALSE;
|
|
||||||
bool easy_owns_conn = (data->easy_conn &&
|
|
||||||
(data->easy_conn->data == easy)) ?
|
|
||||||
TRUE : FALSE;
|
|
||||||
|
|
||||||
/* If the 'state' is not INIT or COMPLETED, we might need to do something
|
premature = (data->mstate < CURLM_STATE_COMPLETED) ? TRUE : FALSE;
|
||||||
nice to put the easy_handle in a good known state when this returns. */
|
easy_owns_conn = (data->easy_conn && (data->easy_conn->data == easy)) ?
|
||||||
if(premature)
|
TRUE : FALSE;
|
||||||
/* this handle is "alive" so we need to count down the total number of
|
|
||||||
alive connections when this is removed */
|
|
||||||
multi->num_alive--;
|
|
||||||
|
|
||||||
if(data->easy_conn &&
|
/* If the 'state' is not INIT or COMPLETED, we might need to do something
|
||||||
(data->easy_conn->send_pipe->size +
|
nice to put the easy_handle in a good known state when this returns. */
|
||||||
data->easy_conn->recv_pipe->size > 1) &&
|
if(premature)
|
||||||
data->mstate > CURLM_STATE_WAITDO &&
|
/* this handle is "alive" so we need to count down the total number of
|
||||||
data->mstate < CURLM_STATE_COMPLETED) {
|
alive connections when this is removed */
|
||||||
/* If the handle is in a pipeline and has started sending off its
|
multi->num_alive--;
|
||||||
request but not received its response yet, we need to close
|
|
||||||
connection. */
|
|
||||||
connclose(data->easy_conn, "Removed with partial response");
|
|
||||||
/* Set connection owner so that Curl_done() closes it.
|
|
||||||
We can sefely do this here since connection is killed. */
|
|
||||||
data->easy_conn->data = easy;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The timer must be shut down before data->multi is set to NULL,
|
if(data->easy_conn &&
|
||||||
else the timenode will remain in the splay tree after
|
(data->easy_conn->send_pipe->size +
|
||||||
curl_easy_cleanup is called. */
|
data->easy_conn->recv_pipe->size > 1) &&
|
||||||
Curl_expire(data, 0);
|
data->mstate > CURLM_STATE_WAITDO &&
|
||||||
|
data->mstate < CURLM_STATE_COMPLETED) {
|
||||||
/* destroy the timeout list that is held in the easy handle */
|
/* If the handle is in a pipeline and has started sending off its
|
||||||
if(data->state.timeoutlist) {
|
request but not received its response yet, we need to close
|
||||||
Curl_llist_destroy(data->state.timeoutlist, NULL);
|
connection. */
|
||||||
data->state.timeoutlist = NULL;
|
connclose(data->easy_conn, "Removed with partial response");
|
||||||
}
|
/* Set connection owner so that Curl_done() closes it.
|
||||||
|
We can sefely do this here since connection is killed. */
|
||||||
if(data->dns.hostcachetype == HCACHE_MULTI) {
|
data->easy_conn->data = easy;
|
||||||
/* stop using the multi handle's DNS cache */
|
|
||||||
data->dns.hostcache = NULL;
|
|
||||||
data->dns.hostcachetype = HCACHE_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(data->easy_conn) {
|
|
||||||
|
|
||||||
/* we must call Curl_done() here (if we still "own it") so that we don't
|
|
||||||
leave a half-baked one around */
|
|
||||||
if(easy_owns_conn) {
|
|
||||||
|
|
||||||
/* Curl_done() clears the conn->data field to lose the association
|
|
||||||
between the easy handle and the connection
|
|
||||||
|
|
||||||
Note that this ignores the return code simply because there's
|
|
||||||
nothing really useful to do with it anyway! */
|
|
||||||
(void)Curl_done(&data->easy_conn, data->result, premature);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
/* Clear connection pipelines, if Curl_done above was not called */
|
|
||||||
Curl_getoff_all_pipelines(data, data->easy_conn);
|
|
||||||
}
|
|
||||||
|
|
||||||
Curl_wildcard_dtor(&data->wildcard);
|
|
||||||
|
|
||||||
/* as this was using a shared connection cache we clear the pointer
|
|
||||||
to that since we're not part of that multi handle anymore */
|
|
||||||
data->state.conn_cache = NULL;
|
|
||||||
|
|
||||||
/* change state without using multistate(), only to make singlesocket() do
|
|
||||||
what we want */
|
|
||||||
data->mstate = CURLM_STATE_COMPLETED;
|
|
||||||
singlesocket(multi, easy); /* to let the application know what sockets
|
|
||||||
that vanish with this handle */
|
|
||||||
|
|
||||||
/* Remove the association between the connection and the handle */
|
|
||||||
if(data->easy_conn) {
|
|
||||||
data->easy_conn->data = NULL;
|
|
||||||
data->easy_conn = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
data->multi = NULL; /* clear the association to this multi handle */
|
|
||||||
|
|
||||||
{
|
|
||||||
/* make sure there's no pending message in the queue sent from this easy
|
|
||||||
handle */
|
|
||||||
struct curl_llist_element *e;
|
|
||||||
|
|
||||||
for(e = multi->msglist->head; e; e = e->next) {
|
|
||||||
struct Curl_message *msg = e->ptr;
|
|
||||||
|
|
||||||
if(msg->extmsg.easy_handle == easy) {
|
|
||||||
Curl_llist_remove(multi->msglist, e, NULL);
|
|
||||||
/* there can only be one from this specific handle */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 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 */
|
|
||||||
|
|
||||||
/* NOTE NOTE NOTE
|
|
||||||
We do not touch the easy handle here! */
|
|
||||||
|
|
||||||
multi->num_easy--; /* one less to care about now */
|
|
||||||
|
|
||||||
update_timer(multi);
|
|
||||||
return CURLM_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* The timer must be shut down before data->multi is set to NULL,
|
||||||
|
else the timenode will remain in the splay tree after
|
||||||
|
curl_easy_cleanup is called. */
|
||||||
|
Curl_expire(data, 0);
|
||||||
|
|
||||||
|
/* destroy the timeout list that is held in the easy handle */
|
||||||
|
if(data->state.timeoutlist) {
|
||||||
|
Curl_llist_destroy(data->state.timeoutlist, NULL);
|
||||||
|
data->state.timeoutlist = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(data->dns.hostcachetype == HCACHE_MULTI) {
|
||||||
|
/* stop using the multi handle's DNS cache */
|
||||||
|
data->dns.hostcache = NULL;
|
||||||
|
data->dns.hostcachetype = HCACHE_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(data->easy_conn) {
|
||||||
|
|
||||||
|
/* we must call Curl_done() here (if we still "own it") so that we don't
|
||||||
|
leave a half-baked one around */
|
||||||
|
if(easy_owns_conn) {
|
||||||
|
|
||||||
|
/* Curl_done() clears the conn->data field to lose the association
|
||||||
|
between the easy handle and the connection
|
||||||
|
|
||||||
|
Note that this ignores the return code simply because there's
|
||||||
|
nothing really useful to do with it anyway! */
|
||||||
|
(void)Curl_done(&data->easy_conn, data->result, premature);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
/* Clear connection pipelines, if Curl_done above was not called */
|
||||||
|
Curl_getoff_all_pipelines(data, data->easy_conn);
|
||||||
|
}
|
||||||
|
|
||||||
|
Curl_wildcard_dtor(&data->wildcard);
|
||||||
|
|
||||||
|
/* as this was using a shared connection cache we clear the pointer to that
|
||||||
|
since we're not part of that multi handle anymore */
|
||||||
|
data->state.conn_cache = NULL;
|
||||||
|
|
||||||
|
/* change state without using multistate(), only to make singlesocket() do
|
||||||
|
what we want */
|
||||||
|
data->mstate = CURLM_STATE_COMPLETED;
|
||||||
|
singlesocket(multi, easy); /* to let the application know what sockets that
|
||||||
|
vanish with this handle */
|
||||||
|
|
||||||
|
/* Remove the association between the connection and the handle */
|
||||||
|
if(data->easy_conn) {
|
||||||
|
data->easy_conn->data = NULL;
|
||||||
|
data->easy_conn = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
data->multi = NULL; /* clear the association to this multi handle */
|
||||||
|
|
||||||
|
/* make sure there's no pending message in the queue sent from this easy
|
||||||
|
handle */
|
||||||
|
|
||||||
|
for(e = multi->msglist->head; e; e = e->next) {
|
||||||
|
struct Curl_message *msg = e->ptr;
|
||||||
|
|
||||||
|
if(msg->extmsg.easy_handle == easy) {
|
||||||
|
Curl_llist_remove(multi->msglist, e, NULL);
|
||||||
|
/* there can only be one from this specific handle */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* make the previous node point to our next */
|
||||||
|
if(data->prev)
|
||||||
|
data->prev->next = data->next;
|
||||||
else
|
else
|
||||||
return CURLM_BAD_EASY_HANDLE; /* twasn't found */
|
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 */
|
||||||
|
|
||||||
|
/* NOTE NOTE NOTE
|
||||||
|
We do not touch the easy handle here! */
|
||||||
|
multi->num_easy--; /* one less to care about now */
|
||||||
|
|
||||||
|
update_timer(multi);
|
||||||
|
return CURLM_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Curl_multi_pipeline_enabled(const struct Curl_multi *multi)
|
bool Curl_multi_pipeline_enabled(const struct Curl_multi *multi)
|
||||||
|
Reference in New Issue
Block a user