~ubuntu-branches/ubuntu/quantal/curl/quantal-updates

« back to all changes in this revision

Viewing changes to tests/libtest/lib560.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Schuldei
  • Date: 2009-04-02 23:35:45 UTC
  • mto: (1.2.1 upstream) (3.2.3 sid)
  • mto: This revision was merged to the branch mainline in revision 38.
  • Revision ID: james.westby@ubuntu.com-20090402233545-geixkwhe3izccjt7
Tags: upstream-7.19.4
ImportĀ upstreamĀ versionĀ 7.19.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 *                                  _   _ ____  _
 
3
 *  Project                     ___| | | |  _ \| |
 
4
 *                             / __| | | | |_) | |
 
5
 *                            | (__| |_| |  _ <| |___
 
6
 *                             \___|\___/|_| \_\_____|
 
7
 *
 
8
 * $Id: lib560.c,v 1.2 2008-11-12 22:26:06 danf Exp $
 
9
 *
 
10
 */
 
11
#include "test.h"
 
12
 
 
13
/*
 
14
 * Simply download a HTTPS file!
 
15
 *
 
16
 * This test was added after the HTTPS-using-multi-interface with OpenSSL
 
17
 * regression of 7.19.1 to hopefully prevent this embarassing mistake from
 
18
 * appearing again... Unfortunately the bug wasn't triggered by this test,
 
19
 * which presumably is because the connect to a local server is too
 
20
 * fast/different compared to the real/distant servers we saw the bug happen
 
21
 * with.
 
22
 */
 
23
int test(char *URL)
 
24
{
 
25
  CURL *http_handle;
 
26
  CURLM *multi_handle;
 
27
 
 
28
  int still_running; /* keep number of running handles */
 
29
 
 
30
  http_handle = curl_easy_init();
 
31
  if (!http_handle)
 
32
    return TEST_ERR_MAJOR_BAD;
 
33
 
 
34
  /* set options */
 
35
  curl_easy_setopt(http_handle, CURLOPT_URL, URL);
 
36
  curl_easy_setopt(http_handle, CURLOPT_HEADER, 1L);
 
37
  curl_easy_setopt(http_handle, CURLOPT_SSL_VERIFYPEER, 0L);
 
38
  curl_easy_setopt(http_handle, CURLOPT_SSL_VERIFYHOST, 0L);
 
39
 
 
40
  /* init a multi stack */
 
41
  multi_handle = curl_multi_init();
 
42
  if (!multi_handle) {
 
43
    curl_easy_cleanup(http_handle);
 
44
    return TEST_ERR_MAJOR_BAD;
 
45
  }
 
46
 
 
47
  /* add the individual transfers */
 
48
  curl_multi_add_handle(multi_handle, http_handle);
 
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
    /* In a real-world program you OF COURSE check the return code of the
 
75
       function calls, *and* you make sure that maxfd is bigger than -1 so
 
76
       that the call to select() below makes sense! */
 
77
 
 
78
    rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
 
79
 
 
80
    switch(rc) {
 
81
    case -1:
 
82
      /* select error */
 
83
      break;
 
84
    case 0:
 
85
    default:
 
86
      /* timeout or readable/writable sockets */
 
87
      while(CURLM_CALL_MULTI_PERFORM ==
 
88
            curl_multi_perform(multi_handle, &still_running));
 
89
      break;
 
90
    }
 
91
  }
 
92
 
 
93
  curl_multi_cleanup(multi_handle);
 
94
 
 
95
  curl_easy_cleanup(http_handle);
 
96
 
 
97
  return 0;
 
98
}