keep count of the number of "alive" handles in a struct member, as otherwise

*multi_socket*() can't return the proper number
This commit is contained in:
Daniel Stenberg 2006-08-02 22:29:29 +00:00
parent 8a38c72c48
commit 159834171e
1 changed files with 15 additions and 11 deletions

View File

@ -121,10 +121,11 @@ struct Curl_multi {
/* We have a linked list with easy handles */ /* We have a linked list with easy handles */
struct Curl_one_easy easy; struct Curl_one_easy easy;
/* This is the amount of entries in the linked list above. */
int num_easy;
int num_msgs; /* total amount of messages in the easy handles */ int num_easy; /* amount of entries in the linked list above. */
int num_msgs; /* amount of messages in the easy handles */
int num_alive; /* amount of easy handles that are added but have not yet
reached COMPLETE state */
/* callback function and user data pointer for the *socket() API */ /* callback function and user data pointer for the *socket() API */
curl_socket_callback socket_cb; curl_socket_callback socket_cb;
@ -171,6 +172,9 @@ static void multistate(struct Curl_one_easy *easy, CURLMstate state)
"STATE: %s => %s handle %p: \n", "STATE: %s => %s handle %p: \n",
statename[oldstate], statename[easy->state], (char *)easy); statename[oldstate], statename[easy->state], (char *)easy);
#endif #endif
if(state == CURLM_STATE_COMPLETED)
/* changing to COMPLETED means there's one less easy handle 'alive' */
easy->easy_handle->multi->num_alive--;
} }
/* /*
@ -352,6 +356,8 @@ CURLMcode curl_multi_add_handle(CURLM *multi_handle,
/* increase the node-counter */ /* increase the node-counter */
multi->num_easy++; multi->num_easy++;
/* increase the alive-counter */
multi->num_alive++;
return CURLM_OK; return CURLM_OK;
} }
@ -901,9 +907,6 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
* then we go to completed and consider this transfer aborted. */ * then we go to completed and consider this transfer aborted. */
multistate(easy, CURLM_STATE_COMPLETED); multistate(easy, CURLM_STATE_COMPLETED);
} }
else
/* this one still lives! */
(*running_handles)++;
} }
} while (easy->easy_handle->change.url_changed); } while (easy->easy_handle->change.url_changed);
@ -943,8 +946,6 @@ CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles)
CURLMcode returncode=CURLM_OK; CURLMcode returncode=CURLM_OK;
struct Curl_tree *t; struct Curl_tree *t;
*running_handles = 0; /* bump this once for every living handle */
if(!GOOD_MULTI_HANDLE(multi)) if(!GOOD_MULTI_HANDLE(multi))
return CURLM_BAD_HANDLE; return CURLM_BAD_HANDLE;
@ -980,6 +981,8 @@ CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles)
} while(t); } while(t);
*running_handles = multi->num_alive;
return returncode; return returncode;
} }
@ -1169,6 +1172,7 @@ static CURLMcode multi_socket(struct Curl_multi *multi,
if(checkall) { if(checkall) {
struct Curl_one_easy *easyp; struct Curl_one_easy *easyp;
/* *perform() deals with running_handles on its own */
result = curl_multi_perform(multi, running_handles); result = curl_multi_perform(multi, running_handles);
/* walk through each easy handle and do the socket state change magic /* walk through each easy handle and do the socket state change magic
@ -1191,9 +1195,6 @@ static CURLMcode multi_socket(struct Curl_multi *multi,
/* unmatched socket, major problemo! */ /* unmatched socket, major problemo! */
return CURLM_BAD_SOCKET; /* better return code? */ return CURLM_BAD_SOCKET; /* better return code? */
/* Now, there is potentially a chain of easy handles in this hash
entry struct and we need to deal with all of them */
data = entry->easy; data = entry->easy;
result = multi_runsingle(multi, data->set.one_easy, running_handles); result = multi_runsingle(multi, data->set.one_easy, running_handles);
@ -1203,6 +1204,8 @@ static CURLMcode multi_socket(struct Curl_multi *multi,
last */ last */
singlesocket(multi, data->set.one_easy); singlesocket(multi, data->set.one_easy);
*running_handles = multi->num_alive;
/* or should we fall-through and do the timer-based stuff? */ /* or should we fall-through and do the timer-based stuff? */
return result; return result;
} }
@ -1245,6 +1248,7 @@ static CURLMcode multi_socket(struct Curl_multi *multi,
} while(t); } while(t);
*running_handles = multi->num_alive;
return result; return result;
} }