-#ifdef USE_CURL_MULTI
-void process_curl_messages();
-void process_request_queue();
-#endif
-
-struct active_request_slot *get_active_slot()
-{
- struct active_request_slot *slot = active_queue_head;
- struct active_request_slot *newslot;
-
-#ifdef USE_CURL_MULTI
- int num_transfers;
-
- /* Wait for a slot to open up if the queue is full */
- while (active_requests >= max_requests) {
- curl_multi_perform(curlm, &num_transfers);
- if (num_transfers < active_requests) {
- process_curl_messages();
- }
- }
-#endif
-
- while (slot != NULL && slot->in_use) {
- slot = slot->next;
- }
- if (slot == NULL) {
- newslot = xmalloc(sizeof(*newslot));
- newslot->curl = curl_easy_duphandle(curl_default);
- newslot->in_use = 0;
- newslot->next = NULL;
-
- slot = active_queue_head;
- if (slot == NULL) {
- active_queue_head = newslot;
- } else {
- while (slot->next != NULL) {
- slot = slot->next;
- }
- slot->next = newslot;
- }
- slot = newslot;
- }
-
- active_requests++;
- slot->in_use = 1;
- slot->done = 0;
- slot->local = NULL;
- curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, pragma_header);
- curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_range_header);
- curl_easy_setopt(slot->curl, CURLOPT_ERRORBUFFER, curl_errorstr);
-
- return slot;
-}
-
-int start_active_slot(struct active_request_slot *slot)
-{
-#ifdef USE_CURL_MULTI
- CURLMcode curlm_result = curl_multi_add_handle(curlm, slot->curl);
-
- if (curlm_result != CURLM_OK &&
- curlm_result != CURLM_CALL_MULTI_PERFORM) {
- active_requests--;
- slot->in_use = 0;
- return 0;
- }
-#endif
- return 1;
-}
-
-void run_active_slot(struct active_request_slot *slot)
-{
-#ifdef USE_CURL_MULTI
- int num_transfers;
- long last_pos = 0;
- long current_pos;
- fd_set readfds;
- fd_set writefds;
- fd_set excfds;
- int max_fd;
- struct timeval select_timeout;
- CURLMcode curlm_result;
-
- while (!slot->done) {
- data_received = 0;
- do {
- curlm_result = curl_multi_perform(curlm,
- &num_transfers);
- } while (curlm_result == CURLM_CALL_MULTI_PERFORM);
- if (num_transfers < active_requests) {
- process_curl_messages();
- process_request_queue();
- }