]> granicus.if.org Git - curl/commitdiff
- Jeff Pohlmeyer improved the hiperfifo.c example to use the
authorDaniel Stenberg <daniel@haxx.se>
Wed, 2 May 2007 13:52:38 +0000 (13:52 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 2 May 2007 13:52:38 +0000 (13:52 +0000)
  CURLMOPT_TIMERFUNCTION callback option.

CHANGES
RELEASE-NOTES
docs/examples/hiperfifo.c

diff --git a/CHANGES b/CHANGES
index d7235d083bb2a4f141565eb4f5f918886c3c04b0..963716f0707ac1a7b1032c72b7875cafc71955ab 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,9 @@
                                   Changelog
 
 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
   when CURLM_CALL_MULTI_PERFORM is returned from curl_multi_socket*/perform,
   to make applications using only curl_multi_socket() to properly function
index 2104664337af0cc995da5e1b8188e0ea389b9101..66726a45ed5e61f4645754f2def919c8647826c0 100644 (file)
@@ -57,6 +57,6 @@ advice from friends like these:
 
  Song Ma, Dan Fandrich, Yang Tse, Jay Austin, Robert Iakobashvil,
  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)
index f640bf9dc9f6c21d2cb1e29a797e42ed218bf7cd..e8d767133cdd9645936a04e3d5daadc579cd0ae5 100644 (file)
@@ -92,18 +92,15 @@ typedef struct _SockInfo {
 
 
 /* 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;
 
-  curl_multi_timeout(g->multi, &timeout_ms);
-  if(timeout_ms < 0)
-    return;
-
   timeout.tv_sec = timeout_ms/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);
+  return 0;
 }
 
 
@@ -185,9 +182,7 @@ static void event_cb(int fd, short kind, void *userp)
   } while (rc == CURLM_CALL_MULTI_PERFORM);
   mcode_or_die("event_cb: curl_multi_socket", rc);
   check_run_count(g);
-  if(g->still_running) {
-    update_timeout(g);
-  } else {
+  if ( g->still_running <= 0 ) {
     fprintf(MSG_OUT, "last transfer done, kill timeout\n");
     if (evtimer_pending(&g->timer_event, NULL)) {
       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);
   mcode_or_die("timer_cb: curl_multi_socket", rc);
   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);
   curl_multi_setopt(g.multi, CURLMOPT_SOCKETFUNCTION, sock_cb);
   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 {
     rc = curl_multi_socket_all(g.multi, &g.still_running);
   } while (CURLM_CALL_MULTI_PERFORM == rc);
-  update_timeout(&g);
   event_dispatch();
   curl_multi_cleanup(g.multi);
   return 0;