mirror of https://github.com/moparisthebest/curl
- Jeff Pohlmeyer improved the hiperfifo.c example to use the
CURLMOPT_TIMERFUNCTION callback option.
This commit is contained in:
parent
2f0539d880
commit
1afb67e31b
3
CHANGES
3
CHANGES
|
@ -7,6 +7,9 @@
|
||||||
Changelog
|
Changelog
|
||||||
|
|
||||||
Daniel S (2 May 2007)
|
Daniel S (2 May 2007)
|
||||||
|
- Jeff Pohlmeyer improved the hiperfifo.c example to use the
|
||||||
|
CURLMOPT_TIMERFUNCTION callback option.
|
||||||
|
|
||||||
- Set the timeout for easy handles to expire really soon after addition or
|
- Set the timeout for easy handles to expire really soon after addition or
|
||||||
when CURLM_CALL_MULTI_PERFORM is returned from curl_multi_socket*/perform,
|
when CURLM_CALL_MULTI_PERFORM is returned from curl_multi_socket*/perform,
|
||||||
to make applications using only curl_multi_socket() to properly function
|
to make applications using only curl_multi_socket() to properly function
|
||||||
|
|
|
@ -57,6 +57,6 @@ advice from friends like these:
|
||||||
|
|
||||||
Song Ma, Dan Fandrich, Yang Tse, Jay Austin, Robert Iakobashvil,
|
Song Ma, Dan Fandrich, Yang Tse, Jay Austin, Robert Iakobashvil,
|
||||||
James Housley, Daniel Black, Steve Little, Sonia Subramanian, Peter O'Gorman,
|
James Housley, Daniel Black, Steve Little, Sonia Subramanian, Peter O'Gorman,
|
||||||
Frank Hempel, Michael Wallner
|
Frank Hempel, Michael Wallner, Jeff Pohlmeyer
|
||||||
|
|
||||||
Thanks! (and sorry if I forgot to mention someone)
|
Thanks! (and sorry if I forgot to mention someone)
|
||||||
|
|
|
@ -92,18 +92,15 @@ typedef struct _SockInfo {
|
||||||
|
|
||||||
|
|
||||||
/* Update the event timer after curl_multi library calls */
|
/* Update the event timer after curl_multi library calls */
|
||||||
static void update_timeout(GlobalInfo *g)
|
static int multi_timer_cb(CURLM *multi, long timeout_ms, GlobalInfo *g)
|
||||||
{
|
{
|
||||||
long timeout_ms;
|
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
|
|
||||||
curl_multi_timeout(g->multi, &timeout_ms);
|
|
||||||
if(timeout_ms < 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
timeout.tv_sec = timeout_ms/1000;
|
timeout.tv_sec = timeout_ms/1000;
|
||||||
timeout.tv_usec = (timeout_ms%1000)*1000;
|
timeout.tv_usec = (timeout_ms%1000)*1000;
|
||||||
|
fprintf(MSG_OUT, "multi_timer_cb: Setting timeout to %ld ms\n", timeout_ms);
|
||||||
evtimer_add(&g->timer_event, &timeout);
|
evtimer_add(&g->timer_event, &timeout);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -185,9 +182,7 @@ static void event_cb(int fd, short kind, void *userp)
|
||||||
} while (rc == CURLM_CALL_MULTI_PERFORM);
|
} while (rc == CURLM_CALL_MULTI_PERFORM);
|
||||||
mcode_or_die("event_cb: curl_multi_socket", rc);
|
mcode_or_die("event_cb: curl_multi_socket", rc);
|
||||||
check_run_count(g);
|
check_run_count(g);
|
||||||
if(g->still_running) {
|
if ( g->still_running <= 0 ) {
|
||||||
update_timeout(g);
|
|
||||||
} else {
|
|
||||||
fprintf(MSG_OUT, "last transfer done, kill timeout\n");
|
fprintf(MSG_OUT, "last transfer done, kill timeout\n");
|
||||||
if (evtimer_pending(&g->timer_event, NULL)) {
|
if (evtimer_pending(&g->timer_event, NULL)) {
|
||||||
evtimer_del(&g->timer_event);
|
evtimer_del(&g->timer_event);
|
||||||
|
@ -210,7 +205,6 @@ static void timer_cb(int fd, short kind, void *userp)
|
||||||
} while (rc == CURLM_CALL_MULTI_PERFORM);
|
} while (rc == CURLM_CALL_MULTI_PERFORM);
|
||||||
mcode_or_die("timer_cb: curl_multi_socket", rc);
|
mcode_or_die("timer_cb: curl_multi_socket", rc);
|
||||||
check_run_count(g);
|
check_run_count(g);
|
||||||
if ( g->still_running ) { update_timeout(g); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -406,10 +400,11 @@ int main(int argc, char **argv)
|
||||||
evtimer_set(&g.timer_event, timer_cb, &g);
|
evtimer_set(&g.timer_event, timer_cb, &g);
|
||||||
curl_multi_setopt(g.multi, CURLMOPT_SOCKETFUNCTION, sock_cb);
|
curl_multi_setopt(g.multi, CURLMOPT_SOCKETFUNCTION, sock_cb);
|
||||||
curl_multi_setopt(g.multi, CURLMOPT_SOCKETDATA, &g);
|
curl_multi_setopt(g.multi, CURLMOPT_SOCKETDATA, &g);
|
||||||
|
curl_multi_setopt(g.multi, CURLMOPT_TIMERFUNCTION, multi_timer_cb);
|
||||||
|
curl_multi_setopt(g.multi, CURLMOPT_TIMERDATA, &g);
|
||||||
do {
|
do {
|
||||||
rc = curl_multi_socket_all(g.multi, &g.still_running);
|
rc = curl_multi_socket_all(g.multi, &g.still_running);
|
||||||
} while (CURLM_CALL_MULTI_PERFORM == rc);
|
} while (CURLM_CALL_MULTI_PERFORM == rc);
|
||||||
update_timeout(&g);
|
|
||||||
event_dispatch();
|
event_dispatch();
|
||||||
curl_multi_cleanup(g.multi);
|
curl_multi_cleanup(g.multi);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue