我有 cURL 的问题。我已经使用curl_multi
了启用的流水线(服务器支持它)。但是我有超过 10000 个单个 URL,我需要下载。我没有那么多免费插座。如何处理?
我已经阅读过 curl_multi_socket_action
,但我找不到一些简单的例子,或者如何修改我的代码
CURLM * curlm = curl_multi_init();
curl_multi_setopt(curlm, CURLMOPT_MAXCONNECTS, 3);
curl_multi_setopt(curlm, CURLMOPT_PIPELINING, 1);
std::vector<CURL_WRITE *> ptrArray;
std::map<MyStringAnsi, MyStringAnsi>::const_iterator it;
for (it = data[0].begin(); it != data[0].end(); it++)
{
CURL_WRITE * curlData = new CURL_WRITE;
curlData->dataIndex = &(it->first);
curlData->threadID = 0;
CURL * curl = InitSingleCURL(it->first, curlData);
curl_multi_add_handle(curlm, curl);
ptrArray.push_back(curlData);
curls.push_back(curl);
}
int still_running = 0;
/* lets start the fetch */
do
{
while(curl_multi_perform(curlm, &still_running) == CURLM_CALL_MULTI_PERFORM);
#ifdef _WIN32
Sleep(10);
#else
usleep(10);
#endif
} while (still_running);