xref: /curl/tests/libtest/lib502.c (revision 25cbc2f7)
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 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 https://curl.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  * SPDX-License-Identifier: curl
22  *
23  ***************************************************************************/
24 #include "test.h"
25 
26 #include "testutil.h"
27 #include "warnless.h"
28 #include "memdebug.h"
29 
30 #define TEST_HANG_TIMEOUT 60 * 1000
31 
32 /*
33  * Get a single URL without select().
34  */
35 
test(char * URL)36 CURLcode test(char *URL)
37 {
38   CURL *c = NULL;
39   CURLM *m = NULL;
40   CURLcode res = CURLE_OK;
41   int running;
42 
43   start_test_timing();
44 
45   global_init(CURL_GLOBAL_ALL);
46 
47   easy_init(c);
48 
49   easy_setopt(c, CURLOPT_URL, URL);
50 
51   multi_init(m);
52 
53   multi_add_handle(m, c);
54 
55   for(;;) {
56     struct timeval timeout;
57     fd_set fdread, fdwrite, fdexcep;
58     int maxfd = -99;
59 
60     timeout.tv_sec = 0;
61     timeout.tv_usec = 100000L; /* 100 ms */
62 
63     multi_perform(m, &running);
64 
65     abort_on_test_timeout();
66 
67     if(!running)
68       break; /* done */
69 
70     FD_ZERO(&fdread);
71     FD_ZERO(&fdwrite);
72     FD_ZERO(&fdexcep);
73 
74     multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
75 
76     /* At this point, maxfd is guaranteed to be greater or equal than -1. */
77 
78     select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
79 
80     abort_on_test_timeout();
81   }
82 
83 test_cleanup:
84 
85   /* proper cleanup sequence - type PA */
86 
87   curl_multi_remove_handle(m, c);
88   curl_multi_cleanup(m);
89   curl_easy_cleanup(c);
90   curl_global_cleanup();
91 
92   return res;
93 }
94