sources: update source headers
[platform/upstream/curl.git] / tests / libtest / lib560.c
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
9  *
10  * This software is licensed as described in the file COPYING, which
11  * you should have received as part of this distribution. The terms
12  * are also available at http://curl.haxx.se/docs/copyright.html.
13  *
14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15  * copies of the Software, and permit persons to whom the Software is
16  * furnished to do so, under the terms of the COPYING file.
17  *
18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19  * KIND, either express or implied.
20  *
21  ***************************************************************************/
22 #include "test.h"
23
24 /*
25  * Simply download a HTTPS file!
26  *
27  * This test was added after the HTTPS-using-multi-interface with OpenSSL
28  * regression of 7.19.1 to hopefully prevent this embarassing mistake from
29  * appearing again... Unfortunately the bug wasn't triggered by this test,
30  * which presumably is because the connect to a local server is too
31  * fast/different compared to the real/distant servers we saw the bug happen
32  * with.
33  */
34 int test(char *URL)
35 {
36   CURL *http_handle;
37   CURLM *multi_handle = NULL;
38   CURLMcode code;
39   int res;
40
41   int still_running; /* keep number of running handles */
42
43   http_handle = curl_easy_init();
44   if (!http_handle)
45     return TEST_ERR_MAJOR_BAD;
46
47   /* set options */
48   test_setopt(http_handle, CURLOPT_URL, URL);
49   test_setopt(http_handle, CURLOPT_HEADER, 1L);
50   test_setopt(http_handle, CURLOPT_SSL_VERIFYPEER, 0L);
51   test_setopt(http_handle, CURLOPT_SSL_VERIFYHOST, 0L);
52
53   /* init a multi stack */
54   multi_handle = curl_multi_init();
55   if (!multi_handle) {
56     curl_easy_cleanup(http_handle);
57     return TEST_ERR_MAJOR_BAD;
58   }
59
60   /* add the individual transfers */
61   curl_multi_add_handle(multi_handle, http_handle);
62
63   /* we start some action by calling perform right away */
64   do {
65     code = curl_multi_perform(multi_handle, &still_running);
66   } while(code == CURLM_CALL_MULTI_PERFORM);
67
68   while(still_running) {
69     struct timeval timeout;
70     int rc; /* select() return code */
71
72     fd_set fdread;
73     fd_set fdwrite;
74     fd_set fdexcep;
75     int maxfd;
76
77     FD_ZERO(&fdread);
78     FD_ZERO(&fdwrite);
79     FD_ZERO(&fdexcep);
80
81     /* set a suitable timeout to play around with */
82     timeout.tv_sec = 1;
83     timeout.tv_usec = 0;
84
85     /* get file descriptors from the transfers */
86     curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
87
88     /* In a real-world program you OF COURSE check the return code of the
89        function calls, *and* you make sure that maxfd is bigger than -1 so
90        that the call to select() below makes sense! */
91
92     rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
93
94     switch(rc) {
95     case -1:
96       /* select error */
97       break;
98     case 0:
99     default:
100       /* timeout or readable/writable sockets */
101       do {
102         code = curl_multi_perform(multi_handle, &still_running);
103       } while(code == CURLM_CALL_MULTI_PERFORM);
104       break;
105     }
106   }
107
108 test_cleanup:
109
110   if(multi_handle)
111     curl_multi_cleanup(multi_handle);
112
113   curl_easy_cleanup(http_handle);
114   curl_global_cleanup();
115
116   return res;
117 }