~ubuntu-branches/ubuntu/warty/curl/warty-security

« back to all changes in this revision

Viewing changes to docs/examples/multi-double.c

  • Committer: Bazaar Package Importer
  • Author(s): Domenico Andreoli
  • Date: 2004-06-04 19:09:25 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040604190925-wy048bp31320r2z6
Tags: 7.12.0.is.7.11.2-1
* Reverted to version 7.11.2 (closes: #252348).
* Disabled support for libidn (closes: #252367). This is to leave
  curl in unstable as much similar as possible to the one in testing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 *                                  _   _ ____  _     
 
3
 *  Project                     ___| | | |  _ \| |    
 
4
 *                             / __| | | | |_) | |    
 
5
 *                            | (__| |_| |  _ <| |___ 
 
6
 *                             \___|\___/|_| \_\_____|
 
7
 *
 
8
 * $Id: multi-double.c,v 1.3 2002/12/03 12:34:43 bagder Exp $
 
9
 *
 
10
 * This is a very simple example using the multi interface.
 
11
 */
 
12
 
 
13
#include <stdio.h>
 
14
#include <string.h>
 
15
 
 
16
/* somewhat unix-specific */
 
17
#include <sys/time.h>
 
18
#include <unistd.h>
 
19
 
 
20
/* curl stuff */
 
21
#include <curl/curl.h>
 
22
 
 
23
/*
 
24
 * Simply download two HTTP files!
 
25
 */
 
26
int main(int argc, char **argv)
 
27
{
 
28
  CURL *http_handle;
 
29
  CURL *http_handle2;
 
30
  CURLM *multi_handle;
 
31
 
 
32
  int still_running; /* keep number of running handles */
 
33
 
 
34
  http_handle = curl_easy_init();
 
35
  http_handle2 = curl_easy_init();
 
36
 
 
37
  /* set options */
 
38
  curl_easy_setopt(http_handle, CURLOPT_URL, "http://www.haxx.se/");
 
39
 
 
40
  /* set options */
 
41
  curl_easy_setopt(http_handle2, CURLOPT_URL, "http://localhost/");
 
42
 
 
43
  /* init a multi stack */
 
44
  multi_handle = curl_multi_init();
 
45
 
 
46
  /* add the individual transfers */
 
47
  curl_multi_add_handle(multi_handle, http_handle);
 
48
  curl_multi_add_handle(multi_handle, http_handle2);
 
49
 
 
50
  /* we start some action by calling perform right away */
 
51
  while(CURLM_CALL_MULTI_PERFORM ==
 
52
        curl_multi_perform(multi_handle, &still_running));
 
53
 
 
54
  while(still_running) {
 
55
    struct timeval timeout;
 
56
    int rc; /* select() return code */
 
57
 
 
58
    fd_set fdread;
 
59
    fd_set fdwrite;
 
60
    fd_set fdexcep;
 
61
    int maxfd;
 
62
 
 
63
    FD_ZERO(&fdread);
 
64
    FD_ZERO(&fdwrite);
 
65
    FD_ZERO(&fdexcep);
 
66
 
 
67
    /* set a suitable timeout to play around with */
 
68
    timeout.tv_sec = 1;
 
69
    timeout.tv_usec = 0;
 
70
 
 
71
    /* get file descriptors from the transfers */
 
72
    curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
 
73
 
 
74
    rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
 
75
 
 
76
    switch(rc) {
 
77
    case -1:
 
78
      /* select error */
 
79
      break;
 
80
    case 0:
 
81
    default:
 
82
      /* timeout or readable/writable sockets */
 
83
      while(CURLM_CALL_MULTI_PERFORM ==
 
84
            curl_multi_perform(multi_handle, &still_running));
 
85
      break;
 
86
    }
 
87
  }
 
88
 
 
89
  curl_multi_cleanup(multi_handle);
 
90
 
 
91
  curl_easy_cleanup(http_handle);
 
92
  curl_easy_cleanup(http_handle2);
 
93
 
 
94
  return 0;
 
95
}