本文整理汇总了C++中curl_multi_info_read函数的典型用法代码示例。如果您正苦于以下问题:C++ curl_multi_info_read函数的具体用法?C++ curl_multi_info_read怎么用?C++ curl_multi_info_read使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了curl_multi_info_read函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: zeb_curl_client_verify_response
void
zeb_curl_client_verify_response (zeb_curl_client_t *self, int status, char *content)
{
do {
struct timeval timeout;
int rc; /* select () return code */
CURLMcode mc; /* curl_multi_fdset () return code */
fd_set fdread;
fd_set fdwrite;
fd_set fdexcep;
int maxfd = -1;
long curl_timeo = -1;
FD_ZERO (&fdread);
FD_ZERO (&fdwrite);
FD_ZERO (&fdexcep);
/* set a suitable timeout to play around with */
timeout.tv_sec = 1;
timeout.tv_usec = 0;
curl_multi_timeout (self->multi_handle, &curl_timeo);
if(curl_timeo >= 0) {
timeout.tv_sec = curl_timeo / 1000;
if(timeout.tv_sec > 1)
timeout.tv_sec = 1;
else
timeout.tv_usec = (curl_timeo % 1000) * 1000;
}
/* get file descriptors from the transfers */
mc = curl_multi_fdset (self->multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
if (mc != CURLM_OK) {
fprintf (stderr, "curl_multi_fdset () failed, code %d.\n", mc);
break;
}
/* On success the value of maxfd is guaranteed to be >= -1. We call
select(maxfd + 1, ...); specially in case of (maxfd == -1) there are
no fds ready yet so we call select(0, ...) --or Sleep() on Windows--
to sleep 100ms, which is the minimum suggested value in the
curl_multi_fdset() doc. */
if (maxfd == -1) {
/* Portable sleep for platforms other than Windows. */
struct timeval wait = { 0, 100 * 1000 }; /* 100ms */
rc = select (0, NULL, NULL, NULL, &wait);
}
else {
/* Note that on some platforms 'timeout' may be modified by select().
If you need access to the original value save a copy beforehand. */
rc = select (maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
}
switch (rc) {
case -1:
/* select error */
break;
case 0: /* timeout */
default: /* action */
curl_multi_perform (self->multi_handle, &self->still_running);
break;
}
} while (self->still_running);
int dontcare;
CURLMsg *msg = NULL;
while ((msg = curl_multi_info_read (self->multi_handle, &dontcare))) {
if (msg->msg == CURLMSG_DONE) {
CURL *curl = msg->easy_handle;
long actual_status;
curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &actual_status);
assert (actual_status == status);
assert (streq (self->data, content));
zstr_free (&self->data);
curl_multi_remove_handle (self->multi_handle, curl);
curl_easy_cleanup (curl);
}
}
}
开发者ID:digideskio,项目名称:zebra,代码行数:85,代码来源:zeb_curl_client.c
示例2: while
bool HTTP::Tick()
{
// curl_multi_perform() returns as soon as the reads/writes are done.
// This function does not require that there actually is any data available for reading or that data can be written, it can be called just in case.
int running_transfers = 0;
int loopcheck = 0;
CURLMcode result = CURLM_CALL_MULTI_PERFORM;
while (result == CURLM_CALL_MULTI_PERFORM)
{
result = curl_multi_perform(multihandle, &running_transfers);
loopcheck++;
assert(loopcheck < 1000 && "infinite loop in HTTP::Tick()");
}
CURLMsg * msg = NULL;
do
{
int msgs_in_queue = 0;
msg = curl_multi_info_read(multihandle, &msgs_in_queue);
if (msg && msg->msg == CURLMSG_DONE)
{
// Handle completion.
CURL * easyhandle = msg->easy_handle;
// Get the url.
std::map <CURL*, REQUEST>::iterator u = easyhandles.find(easyhandle);
assert(u != easyhandles.end() && "corruption in easyhandles map");
std::string url = u->second.url;
if (msg->data.result == CURLE_OK)
{
// Completion.
requests[url].state = HTTPINFO::COMPLETE;
curl_easy_getinfo(easyhandle, CURLINFO_SPEED_DOWNLOAD, &requests[url].speed);
}
else
{
// Failure.
requests[url].state = HTTPINFO::FAILED;
requests[url].error = "unknown";
}
// Cleanup.
curl_easy_cleanup(easyhandle);
fclose(u->second.file);
easyhandles.erase(easyhandle);
}
// Update status.
for (std::map <CURL*, REQUEST>::iterator i = easyhandles.begin(); i != easyhandles.end(); i++)
{
CURL * easyhandle = i->first;
std::map <CURL*, REQUEST>::iterator u = easyhandles.find(easyhandle);
assert(u != easyhandles.end() && "corruption in requestUrls map");
std::string url = u->second.url;
curl_easy_getinfo(easyhandle, CURLINFO_SPEED_DOWNLOAD, &requests[url].speed);
requests[url].state = requests[url].downloaded > 0 ? HTTPINFO::DOWNLOADING : HTTPINFO::CONNECTING;
}
}
while (msg);
downloading = (running_transfers > 0);
return downloading;
}
开发者ID:logzero,项目名称:vdrift,代码行数:66,代码来源:http.cpp
示例3: while
void
Downloader::update()
{
// read data from the network
CURLMcode ret;
int running_handles;
while((ret = curl_multi_perform(m_multi_handle, &running_handles)) == CURLM_CALL_MULTI_PERFORM)
{
log_debug << "updating" << std::endl;
}
// check if any downloads got finished
int msgs_in_queue;
CURLMsg* msg;
while ((msg = curl_multi_info_read(m_multi_handle, &msgs_in_queue)))
{
switch(msg->msg)
{
case CURLMSG_DONE:
{
log_info << "Download completed with " << msg->data.result << std::endl;
curl_multi_remove_handle(m_multi_handle, msg->easy_handle);
auto it = std::find_if(m_transfers.begin(), m_transfers.end(),
[&msg](const std::unique_ptr<Transfer>& rhs) {
return rhs->get_curl_handle() == msg->easy_handle;
});
assert(it != m_transfers.end());
TransferStatusPtr status = (*it)->get_status();
status->error_msg = (*it)->get_error_buffer();
m_transfers.erase(it);
if (msg->data.result == CURLE_OK)
{
bool success = true;
for(auto& callback : status->callbacks)
{
try
{
callback(success);
}
catch(const std::exception& err)
{
success = false;
log_warning << "Exception in Downloader: " << err.what() << std::endl;
status->error_msg = err.what();
}
}
}
else
{
log_warning << "Error: " << curl_easy_strerror(msg->data.result) << std::endl;
for(auto& callback : status->callbacks)
{
try
{
callback(false);
}
catch(const std::exception& err)
{
log_warning << "Illegal exception in Downloader: " << err.what() << std::endl;
}
}
}
}
break;
default:
log_warning << "unhandled cURL message: " << msg->msg << std::endl;
break;
}
}
}
开发者ID:eegorov,项目名称:supertux,代码行数:73,代码来源:downloader.cpp
示例4: logMsg
//.........这里部分代码省略.........
// TODO: if no internet, then this gets stuck... put a timeout here.
while(fdMax < 0 && fdsetTimeoutCount < 20) {
//TODO: Get a better heuristic on the sleep milliseconds
//sleeps for 100 msec and calls perform and fdset to see if multi perform has started its job
std::this_thread::sleep_for(std::chrono::milliseconds(100));
cres = curl_multi_perform(multiHandle, &numHandles);
prevHandle = numHandles;
curl_multi_fdset(multiHandle, &fdRead, &fdWrite, &fdExcep, &fdMax);
std::cout<<"Here\n"; //TODO: Remove this. Its here to test how many times this loop runs till
//multi_perform starts doing stuff
fdsetTimeoutCount++;
}
if(fdMax < 0) {
logMsg("fdMax set timeout: fdmax still not set by curl_multi_fdset. Internet connection??");
for(auto i = 0; i < urls.size(); i++) {
delete out[i];
}
urls.clear();
return false;
}
//select blocks the thread until the fd set by curl is ready with data.
rc = select(fdMax+1, &fdRead, &fdWrite, &fdExcep, &timeout);
// helper variables to convert extracted data to Json on the spot instead of waiting for all urls to be
// fetched and then converting the extracted data to json
char *url;
char *tmpOutData; //to read the CURLINFO_PRIVATE data which is type casted to char* from stringstream*
std::string tmpJsonData;
int length;
std::shared_ptr<Json::Value> jsonVal(new Json::Value);
Json::Reader jsonReader;
// see what select returned
switch(rc) {
case -1:
//select call ERRORed
break;
case 0:
std::cout<<"Here timeout\n"; //TODO: Remove this. Its here to test how many times select times out.
// So far never with 1 sec of timeout.
//select call Timed out. No fd ready to read anything.
fetchTry++;
if(fetchTry == MAX_FETCH_TRY) {
curl_multi_cleanup(multiHandle);
curl_global_cleanup();
for(auto i = 0; i < urls.size(); i++) {
delete out[i];
}
urls.clear();
return false;
}
break;
default:
// sleep for 5 msec to give enough time for curl to read data for any of the file descriptors.
std::this_thread::sleep_for(std::chrono::milliseconds(5));
std::cout<<"Possible Change\n"; //TODO: Remove this. Its here to test how many times fd is ready and
// will result in a complete data read
//Perform again to see what happened with individual easy handles
curl_multi_perform(multiHandle,&numHandles);
// if easy handle status changed some urls are done.
if(prevHandle != numHandles) {
std::cout<<"Change happened\n";//TODO: Remove this. Only here for testing
prevHandle = numHandles;
handleMsg = curl_multi_info_read(multiHandle, &queuedHandles);
// for every url done fill the jsonValue
for(auto qHandItr = 0; qHandItr <= queuedHandles; qHandItr++) {
if(handleMsg->msg == CURLMSG_DONE) {
//get the url from the easyHandle
curl_easy_getinfo(handleMsg->easy_handle, CURLINFO_EFFECTIVE_URL , &url);
//get the tmpOutData which is holding the extracted info from the url
curl_easy_getinfo(handleMsg->easy_handle, CURLINFO_PRIVATE , &tmpOutData);
// typecast back from char* to std::stringstream
tmpJsonData = ((std::stringstream *)tmpOutData)->str();
length = tmpJsonData.size();
jsonReader.parse(tmpJsonData.c_str(), tmpJsonData.c_str() + length, *(jsonVal.get()));
// no way to get what ID this url was for so have to extract ID from url
m_JsonRoots[extractIDFromUrl(std::string(url))] = jsonVal;
logMsg("R: %d - %s <%s>\n", handleMsg->data.result, curl_easy_strerror(handleMsg->data.result), url);
curl_multi_remove_handle(multiHandle, handleMsg->easy_handle);
curl_easy_cleanup(handleMsg->easy_handle);
}
}
}
break;
}
}while(numHandles);
curl_multi_cleanup(multiHandle);
curl_global_cleanup();
}
for(auto i = 0; i < urls.size(); i++) {
delete out[i];
}
urls.clear();
return true;
}
开发者ID:barrycug,项目名称:tangram-es,代码行数:101,代码来源:dataSource.cpp
示例5: curl_multi_info_read
CURLMsg* LLCurl::Multi::info_read(S32* msgs_in_queue)
{
CURLMsg* curlmsg = curl_multi_info_read(mCurlMultiHandle, msgs_in_queue);
return curlmsg;
}
开发者ID:AGoodPerson,项目名称:Ascent,代码行数:5,代码来源:llcurl.cpp
示例6: test
//.........这里部分代码省略.........
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
if ((res = curl_multi_add_handle(multi, p.curl)) != CURLM_OK) {
fprintf(stderr, "curl_multi_add_handle() failed, "
"with code %d\n", res);
curl_multi_cleanup(multi);
curl_easy_cleanup(p.curl);
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
fprintf(stderr, "Going to perform %s\n", (char *)p.accessinfoURL);
ml_timedout = FALSE;
ml_start = tutil_tvnow();
while (!done) {
fd_set rd, wr, exc;
int max_fd;
struct timeval interval;
interval.tv_sec = 1;
interval.tv_usec = 0;
if (tutil_tvdiff(tutil_tvnow(), ml_start) >
MAIN_LOOP_HANG_TIMEOUT) {
ml_timedout = TRUE;
break;
}
mp_timedout = FALSE;
mp_start = tutil_tvnow();
while (res == CURLM_CALL_MULTI_PERFORM) {
res = curl_multi_perform(multi, &running);
if (tutil_tvdiff(tutil_tvnow(), mp_start) >
MULTI_PERFORM_HANG_TIMEOUT) {
mp_timedout = TRUE;
break;
}
fprintf(stderr, "running=%d res=%d\n",running,res);
if (running <= 0) {
done = TRUE;
break;
}
}
if (mp_timedout || done)
break;
if (res != CURLM_OK) {
fprintf(stderr, "not okay???\n");
i = 80;
break;
}
FD_ZERO(&rd);
FD_ZERO(&wr);
FD_ZERO(&exc);
max_fd = 0;
if (curl_multi_fdset(multi, &rd, &wr, &exc, &max_fd) != CURLM_OK) {
fprintf(stderr, "unexpected failured of fdset.\n");
i = 89;
break;
}
if (select_test(max_fd+1, &rd, &wr, &exc, &interval) == -1) {
fprintf(stderr, "bad select??\n");
i =95;
break;
}
res = CURLM_CALL_MULTI_PERFORM;
}
if (ml_timedout || mp_timedout) {
if (ml_timedout) fprintf(stderr, "ml_timedout\n");
if (mp_timedout) fprintf(stderr, "mp_timedout\n");
fprintf(stderr, "ABORTING TEST, since it seems "
"that it would have run forever.\n");
i = TEST_ERR_RUNS_FOREVER;
}
else {
msg = curl_multi_info_read(multi, &running);
/* this should now contain a result code from the easy handle, get it */
if(msg)
i = msg->data.result;
fprintf(stderr, "all done\n");
}
curl_multi_remove_handle(multi, p.curl);
curl_easy_cleanup(p.curl);
curl_multi_cleanup(multi);
curl_global_cleanup();
free(p.accessinfoURL);
return i;
}
开发者ID:tcdog001,项目名称:apv5sdk-v15,代码行数:101,代码来源:lib509.c
示例7: curl_easy_perform
/***************************************************************************
* This function is still only for testing purposes. It makes a great way
* to run the full test suite on the multi interface instead of the easy one.
***************************************************************************
*
* The *new* curl_easy_perform() is the external interface that performs a
* transfer previously setup.
*
* Wrapper-function that: creates a multi handle, adds the easy handle to it,
* runs curl_multi_perform() until the transfer is done, then detaches the
* easy handle, destroys the multi handle and returns the easy handle's return
* code. This will make everything internally use and assume multi interface.
*/
CURLcode curl_easy_perform(CURL *easy)
{
CURLM *multi;
CURLMcode mcode;
CURLcode code = CURLE_OK;
int still_running;
struct timeval timeout;
int rc;
CURLMsg *msg;
fd_set fdread;
fd_set fdwrite;
fd_set fdexcep;
int maxfd;
if(!easy)
return CURLE_BAD_FUNCTION_ARGUMENT;
multi = curl_multi_init();
if(!multi)
return CURLE_OUT_OF_MEMORY;
mcode = curl_multi_add_handle(multi, easy);
if(mcode) {
curl_multi_cleanup(multi);
if(mcode == CURLM_OUT_OF_MEMORY)
return CURLE_OUT_OF_MEMORY;
else
return CURLE_FAILED_INIT;
}
/* we start some action by calling perform right away */
do {
while(CURLM_CALL_MULTI_PERFORM ==
curl_multi_perform(multi, &still_running));
if(!still_running)
break;
FD_ZERO(&fdread);
FD_ZERO(&fdwrite);
FD_ZERO(&fdexcep);
/* timeout once per second */
timeout.tv_sec = 1;
timeout.tv_usec = 0;
/* Old deprecated style: get file descriptors from the transfers */
curl_multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
rc = Curl_select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
/* The way is to extract the sockets and wait for them without using
select. This whole alternative version should probably rather use the
curl_multi_socket() approach. */
if(rc == -1)
/* select error */
break;
/* timeout or data to send/receive => loop! */
} while(still_running);
msg = curl_multi_info_read(multi, &rc);
if(msg)
code = msg->data.result;
mcode = curl_multi_remove_handle(multi, easy);
/* what to do if it fails? */
mcode = curl_multi_cleanup(multi);
/* what to do if it fails? */
return code;
}
开发者ID:bit20062896,项目名称:curl,代码行数:87,代码来源:easy.c
示例8: wait_or_timeout
static CURLcode wait_or_timeout(struct Curl_multi *multi, struct events *ev)
{
bool done = FALSE;
CURLMcode mcode;
CURLcode rc = CURLE_OK;
while(!done) {
CURLMsg *msg;
struct socketmonitor *m;
struct pollfd *f;
struct pollfd fds[4];
int numfds=0;
int pollrc;
int i;
struct timeval before;
struct timeval after;
/* populate the fds[] array */
for(m = ev->list, f=&fds[0]; m; m = m->next) {
f->fd = m->socket.fd;
f->events = m->socket.events;
f->revents = 0;
/* fprintf(stderr, "poll() %d check socket %d\n", numfds, f->fd); */
f++;
numfds++;
}
/* get the time stamp to use to figure out how long poll takes */
before = curlx_tvnow();
/* wait for activity or timeout */
pollrc = Curl_poll(fds, numfds, (int)ev->ms);
after = curlx_tvnow();
ev->msbump = FALSE; /* reset here */
if(0 == pollrc) {
/* timeout! */
ev->ms = 0;
/* fprintf(stderr, "call curl_multi_socket_action( TIMEOUT )\n"); */
mcode = curl_multi_socket_action(multi, CURL_SOCKET_TIMEOUT, 0,
&ev->running_handles);
}
else if(pollrc > 0) {
/* loop over the monitored sockets to see which ones had activity */
for(i = 0; i< numfds; i++) {
if(fds[i].revents) {
/* socket activity, tell libcurl */
int act = poll2cselect(fds[i].revents); /* convert */
infof(multi->easyp, "call curl_multi_socket_action( socket %d )\n",
fds[i].fd);
mcode = curl_multi_socket_action(multi, fds[i].fd, act,
&ev->running_handles);
}
}
if(!ev->msbump)
/* If nothing updated the timeout, we decrease it by the spent time.
* If it was updated, it has the new timeout time stored already.
*/
ev->ms += curlx_tvdiff(after, before);
}
if(mcode)
return CURLE_URL_MALFORMAT; /* TODO: return a proper error! */
/* we don't really care about the "msgs_in_queue" value returned in the
second argument */
msg = curl_multi_info_read(multi, &pollrc);
if(msg) {
rc = msg->data.result;
done = TRUE;
}
}
return rc;
}
开发者ID:princejeru10,项目名称:theswissvet.com,代码行数:78,代码来源:easy.c
示例9: test
int test(char *URL)
{
int res = 0;
CURLM *m = NULL;
CURLMsg *msg; /* for picking up messages with the transfer status */
int msgs_left; /* how many messages are left */
int running;
int handlenum = 0;
struct timeval last_handle_add;
if(parse_url_file("log/urls.txt") <= 0)
goto test_cleanup;
start_test_timing();
curl_global_init(CURL_GLOBAL_ALL);
multi_init(m);
create_handles();
multi_setopt(m, CURLMOPT_PIPELINING, 1L);
multi_setopt(m, CURLMOPT_MAX_HOST_CONNECTIONS, 2L);
multi_setopt(m, CURLMOPT_MAX_PIPELINE_LENGTH, 3L);
multi_setopt(m, CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE, 15000L);
multi_setopt(m, CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE, 10000L);
multi_setopt(m, CURLMOPT_PIPELINING_SITE_BL, site_blacklist);
multi_setopt(m, CURLMOPT_PIPELINING_SERVER_BL, server_blacklist);
last_handle_add = tutil_tvnow();
for(;;) {
struct timeval interval;
struct timeval now;
long int msnow, mslast;
fd_set rd, wr, exc;
int maxfd = -99;
long timeout;
interval.tv_sec = 1;
interval.tv_usec = 0;
if(handlenum < num_handles) {
now = tutil_tvnow();
msnow = now.tv_sec * 1000 + now.tv_usec / 1000;
mslast = last_handle_add.tv_sec * 1000 + last_handle_add.tv_usec / 1000;
if(msnow - mslast >= urltime[handlenum] && handlenum < num_handles) {
fprintf(stdout, "Adding handle %d\n", handlenum);
setup_handle(URL, m, handlenum);
last_handle_add = now;
handlenum++;
}
}
curl_multi_perform(m, &running);
abort_on_test_timeout();
/* See how the transfers went */
while ((msg = curl_multi_info_read(m, &msgs_left))) {
if (msg->msg == CURLMSG_DONE) {
int i, found = 0;
/* Find out which handle this message is about */
for (i = 0; i < num_handles; i++) {
found = (msg->easy_handle == handles[i]);
if(found)
break;
}
printf("Handle %d Completed with status %d\n", i, msg->data.result);
curl_multi_remove_handle(m, handles[i]);
}
}
if(handlenum == num_handles && !running) {
break; /* done */
}
FD_ZERO(&rd);
FD_ZERO(&wr);
FD_ZERO(&exc);
curl_multi_fdset(m, &rd, &wr, &exc, &maxfd);
/* At this point, maxfd is guaranteed to be greater or equal than -1. */
curl_multi_timeout(m, &timeout);
if(timeout < 0)
timeout = 1;
interval.tv_sec = timeout / 1000;
interval.tv_usec = (timeout % 1000) * 1000;
interval.tv_sec = 0;
interval.tv_usec = 1000;
select_test(maxfd+1, &rd, &wr, &exc, &interval);
//.........这里部分代码省略.........
开发者ID:08142008,项目名称:curl,代码行数:101,代码来源:lib1900.c
示例10: main
int main(void)
{
CURLM *cm;
CURLMsg *msg;
long L;
unsigned int C=0;
int M, Q, U = -1;
fd_set R, W, E;
struct timeval T;
int res;
double bytes=0;
long header_bytes=0;
double transfer_time=0;
unsigned long page_size=0;
struct timeval start, stop;
gettimeofday(&start, NULL);
curl_global_init(CURL_GLOBAL_ALL);
cm = curl_multi_init();
/* we can optionally limit the total amount of connections this multi handle
uses */
curl_multi_setopt(cm, CURLMOPT_MAXCONNECTS, (long)MAX);
for(C = 0; C < MAX; ++C) {
init(cm, C);
}
while(U) {
curl_multi_perform(cm, &U);
if(U) {
FD_ZERO(&R);
FD_ZERO(&W);
FD_ZERO(&E);
if(curl_multi_fdset(cm, &R, &W, &E, &M)) {
fprintf(stderr, "E: curl_multi_fdset\n");
return EXIT_FAILURE;
}
if(curl_multi_timeout(cm, &L)) {
fprintf(stderr, "E: curl_multi_timeout\n");
return EXIT_FAILURE;
}
if(L == -1)
L = 100;
if(M == -1) {
#ifdef WIN32
Sleep(L);
#else
sleep((unsigned int)L / 1000);
#endif
}
else {
T.tv_sec = L/1000;
T.tv_usec = (L%1000)*1000;
if(0 > select(M+1, &R, &W, &E, &T)) {
fprintf(stderr, "E: select(%i,,,,%li): %i: %s\n",
M+1, L, errno, strerror(errno));
return EXIT_FAILURE;
}
}
}
while((msg = curl_multi_info_read(cm, &Q))) {
if(msg->msg == CURLMSG_DONE) {
char *url;
CURL *e = msg->easy_handle;
curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &url);
fprintf(stderr, "R: %d - %s <%s>\n",
msg->data.result, curl_easy_strerror(msg->data.result), url);
if((res = curl_easy_getinfo(msg->easy_handle, CURLINFO_SIZE_DOWNLOAD, &bytes)) != CURLE_OK ||
(res = curl_easy_getinfo(msg->easy_handle, CURLINFO_HEADER_SIZE, &header_bytes)) != CURLE_OK ||
(res = curl_easy_getinfo(msg->easy_handle, CURLINFO_TOTAL_TIME, &transfer_time)) != CURLE_OK ) {
fprintf(stderr, "cURL error: %s\n", curl_easy_strerror(res));
}
gettimeofday(&stop, NULL);
page_size+=(long)bytes+header_bytes;
double time=((stop.tv_sec - start.tv_sec) * 1000 + (stop.tv_usec - start.tv_usec) / 1000);
printf("[%f]Time: %f Size: %lu\n", time,transfer_time, (long)bytes+header_bytes);
curl_multi_remove_handle(cm, e);
curl_easy_cleanup(e);
}
else {
fprintf(stderr, "E: CURLMsg (%d)\n", msg->msg);
}
if(C < CNT) {
init(cm, C++);
U++; /* just to prevent it from remaining at 0 if there are more
URLs to get */
}
}
}
curl_multi_cleanup(cm);
//.........这里部分代码省略.........
开发者ID:timir007,项目名称:h1-h2-comp-libcurl,代码行数:101,代码来源:https-loader.c
示例11: curlFetch
/*
FIXME dont run every time, only if dlqueue is full!!!
*/
int curlFetch(struct url *ptr, int dlnum)
{
CURLM *cm;
CURLMsg *msg;
long L=100;
unsigned int C=0;
int M, Q, U = -1;
fd_set R, W, E;
struct timeval T;
CURLMcode ret;
qboolean got404=false;
if (!cls.downloadServer)
return 0;
curl_global_init(CURL_GLOBAL_ALL);
cm = curl_multi_init();
curl_easy_setopt(cm, CURLMOPT_MAXCONNECTS, (long)MAX);
for (C = 0; C < dlnum; ++C)
init(cm, C);
while (U)
{
ret = curl_multi_perform(cm, &U);
if (U)
{
FD_ZERO(&R);
FD_ZERO(&W);
FD_ZERO(&E);
if (ret != CURLM_OK)
{
Com_Printf ("curl_multi_perform error, Aborting HTTP downloads.\n");
return 1;
}
if (curl_multi_fdset(cm, &R, &W, &E, &M)) {
Com_Printf("E: curl_multi_fdset\n");
return 1;
}
if (L == -1)
L = 100;
if (M == -1) {
/* obviously we need to sleep a
short while so we DO NOT RUN OUT OF FDs! */
#ifdef WIN32
Sleep(L);
#else
sleep(L / 1000);
#endif
} else {
T.tv_sec = L/1000;
T.tv_usec = (L%1000)*1000;
//T.tv_sec = 5;
//T.tv_usec = 0;
if (0 > select(M+1, &R, &W, &E, &T)) {
Com_Printf("E: select(%i,,,,%li): %i: %s\n",
M+1, L, errno, strerror(errno));
return 1;
}
}
}
while ((msg = curl_multi_info_read(cm, &Q))) {
// allow user to use console
CL_SendCommand ();
if (msg->msg == CURLMSG_DONE)
{
long responseCode;
extern struct MemoryStruct *memPtr;
char *url;
double recvsize;
double totaltime;
char *localfile;
char *fullurl;
int remainingFiles;
static int finishcnt;
CURL *e = msg->easy_handle;
curl_easy_getinfo(msg->easy_handle, CURLINFO_RESPONSE_CODE, &responseCode);
curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &url);
curl_easy_getinfo(msg->easy_handle, CURLINFO_SIZE_DOWNLOAD, &recvsize);
curl_easy_getinfo(msg->easy_handle, CURLINFO_TOTAL_TIME, &totaltime);
curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &localfile);
curl_easy_getinfo(msg->easy_handle, CURLINFO_EFFECTIVE_URL, &fullurl);
remainingFiles=0;
//.........这里部分代码省略.........
开发者ID:wavecollapser,项目名称:nofuzz-quake2,代码行数:101,代码来源:cl_http.c
示例12: main
//.........这里部分代码省略.........
curl_multi_setopt(multi_handle, CURLMOPT_PUSHFUNCTION, server_push_callback);
curl_multi_setopt(multi_handle, CURLMOPT_PUSHDATA, &transfers);
/* we start some action by calling perform right away */
curl_multi_perform(multi_handle, &still_running);
do {
struct timeval timeout;
int rc; /* select() return code */
CURLMcode mc; /* curl_multi_fdset() return code */
fd_set fdread;
fd_set fdwrite;
fd_set fdexcep;
int maxfd = -1;
long curl_timeo = -1;
FD_ZERO(&fdread);
FD_ZERO(&fdwrite);
FD_ZERO(&fdexcep);
/* set a suitable timeout to play around with */
timeout.tv_sec = 1;
timeout.tv_usec = 0;
curl_multi_timeout(multi_handle, &curl_timeo);
if(curl_timeo >= 0) {
timeout.tv_sec = curl_timeo / 1000;
if(timeout.tv_sec > 1)
timeout.tv_sec = 1;
else
timeout.tv_usec = (curl_timeo % 1000) * 1000;
}
/* get file descriptors from the transfers */
mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
if(mc != CURLM_OK) {
fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc);
break;
}
/* On success the value of maxfd is guaranteed to be >= -1. We call
select(maxfd + 1, ...); specially in case of (maxfd == -1) there are
no fds ready yet so we call select(0, ...) --or Sleep() on Windows--
to sleep 100ms, which is the minimum suggested value in the
curl_multi_fdset() doc. */
if(maxfd == -1) {
#ifdef _WIN32
Sleep(100);
rc = 0;
#else
/* Portable sleep for platforms other than Windows. */
struct timeval wait = { 0, 100 * 1000 }; /* 100ms */
rc = select(0, NULL, NULL, NULL, &wait);
#endif
}
else {
/* Note that on some platforms 'timeout' may be modified by select().
If you need access to the original value save a copy beforehand. */
rc = select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
}
switch(rc) {
case -1:
/* select error */
break;
case 0:
default:
/* timeout or readable/writable sockets */
curl_multi_perform(multi_handle, &still_running);
break;
}
/*
* A little caution when doing server push is that libcurl itself has
* created and added one or more easy handles but we need to clean them up
* when we are done.
*/
do {
int msgq = 0;;
m = curl_multi_info_read(multi_handle, &msgq);
if(m && (m->msg == CURLMSG_DONE)) {
CURL *e = m->easy_handle;
transfers--;
curl_multi_remove_handle(multi_handle, e);
curl_easy_cleanup(e);
}
} while(m);
} while(transfers); /* as long as we have transfers going */
curl_multi_cleanup(multi_handle);
return 0;
}
开发者ID:syslover33,项目名称:ctank,代码行数:101,代码来源:http2-serverpush.c
示例13: tr_webThreadFunc
static void
tr_webThreadFunc( void * vsession )
{
int unused;
CURLM * multi;
struct tr_web * web;
int taskCount = 0;
tr_session * session = vsession;
/* try to enable ssl for https support; but if that fails,
* try a plain vanilla init */
if( curl_global_init( CURL_GLOBAL_SSL ) )
curl_global_init( 0 );
web = tr_new0( struct tr_web, 1 );
web->close_mode = ~0;
web->taskLock = tr_lockNew( );
web->tasks = NULL;
multi = curl_multi_init( );
session->web = web;
for( ;; )
{
long msec;
CURLMsg * msg;
CURLMcode mcode;
struct tr_web_task * task;
if( web->close_mode == TR_WEB_CLOSE_NOW )
break;
if( ( web->close_mode == TR_WEB_CLOSE_WHEN_IDLE ) && !taskCount )
break;
/* add tasks from the queue */
tr_lockLock( web->taskLock );
while(( task = tr_list_pop_front( &web->tasks )))
{
curl_multi_add_handle( multi, createEasy( session, task ));
/*fprintf( stderr, "adding a task.. taskCount is now %d\n", taskCount );*/
++taskCount;
}
tr_lockUnlock( web->taskLock );
/* maybe wait a little while before calling curl_multi_perform() */
msec = 0;
curl_multi_timeout( multi, &msec );
if( msec < 0 )
msec = THREADFUNC_MAX_SLEEP_MSEC;
if( msec > 0 )
{
int usec;
int max_fd;
struct timeval t;
fd_set r_fd_set, w_fd_set, c_fd_set;
max_fd = 0;
FD_ZERO( &r_fd_set );
FD_ZERO( &w_fd_set );
FD_ZERO( &c_fd_set );
curl_multi_fdset( multi, &r_fd_set, &w_fd_set, &c_fd_set, &max_fd );
if( msec > THREADFUNC_MAX_SLEEP_MSEC )
msec = THREADFUNC_MAX_SLEEP_MSEC;
usec = msec * 1000;
t.tv_sec = usec / 1000000;
t.tv_usec = usec % 1000000;
tr_select( max_fd+1, &r_fd_set, &w_fd_set, &c_fd_set, &t );
}
/* call curl_multi_perform() */
do {
mcode = curl_multi_perform( multi, &unused );
} while( mcode == CURLM_CALL_MULTI_PERFORM );
/* pump completed tasks from the multi */
while(( msg = curl_multi_info_read( multi, &unused )))
{
if(( msg->msg == CURLMSG_DONE ) && ( msg->easy_handle != NULL ))
{
struct tr_web_task * task;
CURL * e = msg->easy_handle;
curl_easy_getinfo( e, CURLINFO_PRIVATE, (void*)&task );
curl_easy_getinfo( e, CURLINFO_RESPONSE_CODE, &task->code );
curl_multi_remove_handle( multi, e );
curl_easy_cleanup( e );
/*fprintf( stderr, "removing a completed task.. taskCount is now %d (response code: %d, response len: %d)\n", taskCount, (int)task->code, (int)EVBUFFER_LENGTH(task->response) );*/
tr_runInEventThread( task->session, task_finish_func, task );
--taskCount;
}
}
}
/* cleanup */
curl_multi_cleanup( multi );
tr_lockFree( web->taskLock );
tr_free( web );
session->web = NULL;
}
开发者ID:Longinus00,项目名称:transmission,代码行数:100,代码来源:web.c
示例14: runWebCallBacks
void runWebCallBacks(JSContext *cx){
if(!curlHandle)
return;
int p;
curl_multi_perform(curlHandle, &p);
CURLMsg *msg = NULL;
while( msg = curl_multi_info_read(curlHandle,&p)){
if( msg->msg == CURLMSG_DONE ) {
if( msg->data.result == CURLE_OK){
JSObject *ob = NULL;
ob = JS_NewObject(cx,&webRespClass,NULL,NULL);
if(!ob){
fprint(stderr,"Error creating http response javascript object\n");
exit(EXIT_FAILURE);
}
JS_SetPrivate(cx,ob,msg);
static JSFunctionSpec responseFuncSpec[3]= {
JS_FS("toString", webRspData,0,0),
JS_FS("getImage", webRspGetImg,0,0),
//JS_FS("hasHeaderLine", webRspHL,0,0),
JS_FS_END
};
if(!JS_DefineFunctions(cx, ob, responseFuncSpec))
fprint(stderr,"Unable to create http response object\n");
//Create an instance of webResponseObject, with private data set.
jsval result;
jsval oj = OBJECT_TO_JSVAL(ob);
rqPrivate *rq = NULL;
curl_easy_getinfo(msg->easy_handle,CURLINFO_PRIVATE,(char**)&rq);
if(!rq){
fprint(stderr,"Error retrieving data from the handle");
exit( EXIT_FAILURE);
}
JS_CallFunctionValue(cx, NULL,rq->success, 1, &oj , &result);
} else { /* Just return error string -> Cleanup now */
char *errCode = (char*)curl_easy_strerror(msg->data.result);
if(!errCode)
errCode = "FAILED WITH NO REASON GIVEN";
JSString *string;
string = JS_NewStringCopyZ(cx, errCode);
jsval result, errString = STRING_TO_JSVAL(string);
rqPrivate *rq = NULL;
curl_easy_getinfo(msg->easy_handle,CURLINFO_PRIVATE,(char**)&rq);
if(!rq){
fprint(stderr,"Error retrieving data from the handle");
exit( EXIT_FAILURE);
}
JS_CallFunctionValue(cx, NULL,rq->failure, 1, &errString, &result);
curl_multi_remove_handle(curlHandle,msg->easy_handle);
if(rq->data)
free(rq->data);
free(rq);
curl_easy_cleanup(msg->easy_handle);
}
}
}
}
开发者ID:joejoyce,项目名称:jsEngine,代码行数:66,代码来源:web.cpp
示例15: start_async_http_req
//.........这里部分代码省略.........
if (ctype) {
w_curl_easy_setopt(handle, CURLOPT_HEADERFUNCTION, header_func);
w_curl_easy_setopt(handle, CURLOPT_HEADERDATA, ctype);
}
if (ssl_capath)
w_curl_easy_setopt(handle, CURLOPT_CAPATH, ssl_capath);
if (!ssl_verifypeer)
w_curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0L);
if (!ssl_verifyhost)
w_curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0L);
curl_multi_add_handle(multi_handle, handle);
timeout = connection_timeout_ms;
/* obtain a read fd in "connection_timeout" seconds at worst */
for (timeout = connection_timeout_ms; timeout > 0; timeout -= busy_wait) {
mrc = curl_multi_perform(multi_handle, &running_handles);
if (mrc != CURLM_OK) {
LM_ERR("curl_multi_perform: %s\n", curl_multi_strerror(mrc));
goto error;
}
mrc = curl_multi_timeout(multi_handle, &retry_time);
if (mrc != CURLM_OK) {
LM_ERR("curl_multi_timeout: %s\n", curl_multi_strerror(mrc));
goto error;
}
if (retry_time == -1) {
LM_INFO("curl_multi_timeout() returned -1, pausing %ldms...\n",
sleep_on_bad_timeout);
busy_wait = sleep_on_bad_timeout;
usleep(1000UL * busy_wait);
continue;
}
busy_wait = retry_time < timeout ? retry_time : timeout;
/**
* libcurl is currently stuck in internal operations (connect)
* we have to wait a bit until we receive a read fd
*/
for (i = 0; i < busy_wait; i += check_time) {
/* transfer may have already been completed!! */
while ((cmsg = curl_multi_info_read(multi_handle, &msgs_in_queue))) {
if (cmsg->easy_handle == handle && cmsg->msg == CURLMSG_DONE) {
LM_DBG("done, no need for async!\n");
clean_header_list;
*out_handle = handle;
return ASYNC_SYNC;
}
}
FD_ZERO(&rset);
mrc = curl_multi_fdset(multi_handle, &rset, &wset, &eset, &max_fd);
if (mrc != CURLM_OK) {
LM_ERR("curl_multi_fdset: %s\n", curl_multi_strerror(mrc));
goto error;
}
if (max_fd != -1) {
for (fd = 0; fd <= max_fd; fd++) {
if (FD_ISSET(fd, &rset)) {
LM_DBG(" >>>>>>>>>> fd %d ISSET(read)\n", fd);
if (is_new_transfer(fd)) {
LM_DBG("add fd to read list: %d\n", fd);
add_transfer(fd);
goto success;
}
}
}
}
usleep(1000UL * check_time);
}
}
LM_ERR("timeout while connecting to '%s' (%ld sec)\n", url, connection_timeout);
goto error;
success:
clean_header_list;
*out_handle = handle;
return fd;
error:
mrc = curl_multi_remove_handle(multi_handle, handle);
if (mrc != CURLM_OK)
LM_ERR("curl_multi_remove_handle: %s\n", curl_multi_strerror(mrc));
cleanup:
clean_header_list;
curl_easy_cleanup(handle);
return ASYNC_NO_IO;
}
开发者ID:ihassin,项目名称:opensips,代码行数:101,代码来源:rest_methods.c
示例16: test
int test(char *URL)
{
CURL *easy = NULL;
CURLM *multi = NULL;
int res = 0;
int running;
int msgs_left;
int phase;
CURLMsg *msg;
start_test_timing();
res_global_init(CURL_GLOBAL_ALL);
if(res) {
return res;
}
easy_init(easy);
multi_init(multi);
for (phase = CONNECT_ONLY_PHASE; phase < LAST_PHASE; ++phase) {
/* go verbose */
easy_setopt(easy, CURLOPT_VERBOSE, 1L);
/* specify target */
easy_setopt(easy, CURLOPT_URL, URL);
/* enable 'CONNECT_ONLY' option when in connect phase */
if (phase == CONNECT_ONLY_PHASE)
easy_setopt(easy, CURLOPT_CONNECT_ONLY, 1L);
/* enable 'NOBODY' option to send 'QUIT' command in quit phase */
if (phase == QUIT_PHASE) {
easy_setopt(easy, CURLOPT_CONNECT_ONLY, 0L);
easy_setopt(easy, CURLOPT_NOBODY, 1L);
easy_setopt(easy, CURLOPT_FORBID_REUSE, 1L);
}
multi_add_handle(multi, easy);
for(;;) {
struct timeval interval;
fd_set fdread;
fd_set fdwrite;
fd_set fdexcep;
long timeout = -99;
int maxfd = -99;
multi_perform(multi, &running);
abort_on_test_timeout();
if(!running)
break; /* done */
FD_ZERO(&fdread);
FD_ZERO(&fdwrite);
FD_ZERO(&fdexcep);
multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
/* At this point, maxfd is guaranteed to be greater or equal than -1. */
multi_timeout(multi, &timeout);
/* At this point, timeout is guaranteed to be greater or equal than -1. */
if(timeout != -1L) {
int itimeout = (timeout > (long)INT_MAX) ? INT_MAX : (int)timeout;
interval.tv_sec = itimeout/1000;
interval.tv_usec = (itimeout%1000)*1000;
}
else {
|
请发表评论