~vorlon/ubuntu/natty/curl/multiarch

« back to all changes in this revision

Viewing changes to docs/examples/hiperfifo.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2009-04-29 11:10:29 UTC
  • mfrom: (3.2.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090429111029-2j5eiyokfw2bw049
Tags: 7.19.4-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Drop build dependencies: stunnel, libdb4.6-dev, libssh2-1-dev
  - Add build-dependency on openssh-server
  - Drop libssh2-1-dev from libcurl4-openssl-dev's Depends.
  - Call automake-1.9 with --add-missing --copy --force
* drop debian/patches/security_CVE-2009-0037.patch 
  - this patch is part of 7.19.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *                            | (__| |_| |  _ <| |___
6
6
 *                             \___|\___/|_| \_\_____|
7
7
 *
8
 
 * $Id: hiperfifo.c,v 1.7 2008-05-22 21:20:09 danf Exp $
 
8
 * $Id: hiperfifo.c,v 1.9 2008-11-19 15:31:55 bagder Exp $
9
9
 *
10
10
 * Example application source code using the multi socket interface to
11
11
 * download many files at once.
180
180
{
181
181
  GlobalInfo *g = (GlobalInfo*) userp;
182
182
  CURLMcode rc;
183
 
  (void)kind; /* unused */
 
183
 
 
184
  int action =
 
185
    (kind&EV_READ?CURL_CSELECT_IN:0)|
 
186
    (kind&EV_WRITE?CURL_CSELECT_OUT:0);
184
187
 
185
188
  do {
186
 
    rc = curl_multi_socket(g->multi, fd, &g->still_running);
 
189
    rc = curl_multi_socket_action(g->multi, fd, action, &g->still_running);
187
190
  } while (rc == CURLM_CALL_MULTI_PERFORM);
188
 
  mcode_or_die("event_cb: curl_multi_socket", rc);
 
191
 
 
192
  mcode_or_die("event_cb: curl_multi_socket_action", rc);
 
193
 
189
194
  check_run_count(g);
190
195
  if ( g->still_running <= 0 ) {
191
196
    fprintf(MSG_OUT, "last transfer done, kill timeout\n");
206
211
  (void)kind;
207
212
 
208
213
  do {
209
 
    rc = curl_multi_socket(g->multi, CURL_SOCKET_TIMEOUT, &g->still_running);
 
214
    rc = curl_multi_socket_action(g->multi,
 
215
                                  CURL_SOCKET_TIMEOUT, 0, &g->still_running);
210
216
  } while (rc == CURLM_CALL_MULTI_PERFORM);
211
 
  mcode_or_die("timer_cb: curl_multi_socket", rc);
 
217
  mcode_or_die("timer_cb: curl_multi_socket_action", rc);
212
218
  check_run_count(g);
213
219
}
214
220
 
337
343
          "Adding easy %p to multi %p (%s)\n", conn->easy, g->multi, url);
338
344
  rc =curl_multi_add_handle(g->multi, conn->easy);
339
345
  mcode_or_die("new_conn: curl_multi_add_handle", rc);
340
 
  do {
341
 
    rc = curl_multi_socket_all(g->multi, &g->still_running);
342
 
  } while (CURLM_CALL_MULTI_PERFORM == rc);
343
 
  mcode_or_die("new_conn: curl_multi_socket_all", rc);
344
 
  check_run_count(g);
 
346
 
 
347
  /* note that the add_handle() will set a time-out to trigger very soon so
 
348
     that the necessary socket_action() call will be called by this app */
345
349
}
346
350
 
347
351
/* This gets called whenever data is received from the fifo */
400
404
int main(int argc, char **argv)
401
405
{
402
406
  GlobalInfo g;
403
 
  CURLMcode rc;
404
407
  (void)argc;
405
408
  (void)argv;
406
409
 
409
412
  init_fifo(&g);
410
413
  g.multi = curl_multi_init();
411
414
  evtimer_set(&g.timer_event, timer_cb, &g);
 
415
 
 
416
  /* setup the generic multi interface options we want */
412
417
  curl_multi_setopt(g.multi, CURLMOPT_SOCKETFUNCTION, sock_cb);
413
418
  curl_multi_setopt(g.multi, CURLMOPT_SOCKETDATA, &g);
414
419
  curl_multi_setopt(g.multi, CURLMOPT_TIMERFUNCTION, multi_timer_cb);
415
420
  curl_multi_setopt(g.multi, CURLMOPT_TIMERDATA, &g);
416
 
  do {
417
 
    rc = curl_multi_socket_all(g.multi, &g.still_running);
418
 
  } while (CURLM_CALL_MULTI_PERFORM == rc);
 
421
 
 
422
  /* we don't call any curl_multi_socket*() function yet as we have no handles
 
423
     added! */
 
424
 
419
425
  event_dispatch();
420
426
  curl_multi_cleanup(g.multi);
421
427
  return 0;