-void process_curl_messages()
-{
- int num_messages;
- struct active_request_slot *slot;
- struct transfer_request *request = NULL;
- CURLMsg *curl_message = curl_multi_info_read(curlm, &num_messages);
-
- while (curl_message != NULL) {
- if (curl_message->msg == CURLMSG_DONE) {
- slot = active_queue_head;
- while (slot != NULL &&
- slot->curl != curl_message->easy_handle)
- slot = slot->next;
- if (slot != NULL) {
- curl_multi_remove_handle(curlm, slot->curl);
- active_requests--;
- slot->done = 1;
- slot->in_use = 0;
- slot->curl_result = curl_message->data.result;
- request = request_queue_head;
- while (request != NULL &&
- request->slot != slot)
- request = request->next;
- } else {
- fprintf(stderr, "Received DONE message for unknown request!\n");
- }
- if (request != NULL) {
- request->curl_result =
- curl_message->data.result;
- curl_easy_getinfo(slot->curl,
- CURLINFO_HTTP_CODE,
- &request->http_code);
- request->slot = NULL;
-
- /* Use alternates if necessary */
- if (request->http_code == 404 &&
- request->repo->next != NULL) {
- request->repo = request->repo->next;
- start_request(request);
- } else {
- finish_request(request);
- request->state = COMPLETE;
- }
- }
- } else {
- fprintf(stderr, "Unknown CURL message received: %d\n",
- (int)curl_message->msg);
- }
- curl_message = curl_multi_info_read(curlm, &num_messages);
- }
-}
-
-void process_request_queue()