xref: /curl/tests/libtest/lib564.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 <fcntl.h>
27 
28 #include "testutil.h"
29 #include "warnless.h"
30 #include "memdebug.h"
31 
32 #define TEST_HANG_TIMEOUT 60 * 1000
33 
test(char * URL)34 CURLcode test(char *URL)
35 {
36   CURLcode res = CURLE_OK;
37   CURL *curl = NULL;
38   int running;
39   CURLM *m = NULL;
40 
41   start_test_timing();
42 
43   global_init(CURL_GLOBAL_ALL);
44 
45   easy_init(curl);
46 
47   easy_setopt(curl, CURLOPT_URL, URL);
48   easy_setopt(curl, CURLOPT_VERBOSE, 1L);
49   easy_setopt(curl, CURLOPT_PROXY, libtest_arg2);
50   easy_setopt(curl, CURLOPT_PROXYTYPE, (long)CURLPROXY_SOCKS4);
51 
52   multi_init(m);
53 
54   multi_add_handle(m, curl);
55 
56   fprintf(stderr, "Start at URL 0\n");
57 
58   for(;;) {
59     struct timeval interval;
60     fd_set rd, wr, exc;
61     int maxfd = -99;
62 
63     interval.tv_sec = 1;
64     interval.tv_usec = 0;
65 
66     multi_perform(m, &running);
67 
68     abort_on_test_timeout();
69 
70     if(!running)
71       break; /* done */
72 
73     FD_ZERO(&rd);
74     FD_ZERO(&wr);
75     FD_ZERO(&exc);
76 
77     multi_fdset(m, &rd, &wr, &exc, &maxfd);
78 
79     /* At this point, maxfd is guaranteed to be greater or equal than -1. */
80 
81     select_test(maxfd + 1, &rd, &wr, &exc, &interval);
82 
83     abort_on_test_timeout();
84   }
85 
86 test_cleanup:
87 
88   /* undocumented cleanup sequence - type UB */
89 
90   curl_easy_cleanup(curl);
91   curl_multi_cleanup(m);
92   curl_global_cleanup();
93 
94   return res;
95 }
96