1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
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.haxx.se/docs/copyright.html.
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.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
24 * Check for bugs #1303 and #1327: libcurl should never remove DNS entries
25 * created via CURLOPT_RESOLVE, neither after DNS_CACHE_TIMEOUT elapses
26 * (test1515) nor a dead connection is detected (test1616).
34 #define TEST_HANG_TIMEOUT 60 * 1000
38 #if defined(WIN32) || defined(_WIN32)
39 #define sleep(s) Sleep(s * 1000)
42 static int debug_callback(CURL *curl, curl_infotype info, char *msg,
43 size_t len, void *ptr)
48 if(info == CURLINFO_TEXT)
49 fprintf(stderr, "debug: %.*s", (int) len, msg);
54 static int do_one_request(CURLM *m, char *URL, char *resolve)
57 struct curl_slist *resolve_list = NULL;
63 resolve_list = curl_slist_append(resolve_list, resolve);
67 easy_setopt(curls, CURLOPT_URL, URL);
68 easy_setopt(curls, CURLOPT_RESOLVE, resolve_list);
69 easy_setopt(curls, CURLOPT_DEBUGFUNCTION, debug_callback);
70 easy_setopt(curls, CURLOPT_VERBOSE, 1);
71 easy_setopt(curls, CURLOPT_DNS_CACHE_TIMEOUT, DNS_TIMEOUT);
73 multi_add_handle(m, curls);
74 multi_perform(m, &still_running);
76 abort_on_test_timeout();
78 while(still_running) {
79 struct timeval timeout;
80 fd_set fdread, fdwrite, fdexcep;
89 multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
90 select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
92 abort_on_test_timeout();
93 multi_perform(m, &still_running);
95 abort_on_test_timeout();
98 while((msg = curl_multi_info_read(m, &msgs_left))) {
99 if(msg->msg == CURLMSG_DONE && msg->easy_handle == curls) {
100 res = msg->data.result;
107 curl_multi_remove_handle(m, curls);
108 curl_easy_cleanup(curls);
109 curl_slist_free_all(resolve_list);
118 char *address = libtest_arg2;
119 char *port = libtest_arg3;
125 snprintf(dns_entry, sizeof(dns_entry), "testserver.example.com:%s:%s",
130 global_init(CURL_GLOBAL_ALL);
133 for(i = 1; i <= count; i++) {
134 char target_url[256];
135 snprintf(target_url, sizeof(target_url),
136 "http://testserver.example.com:%s/%s%04d", port, path, i);
138 /* second request must succeed like the first one */
139 res = do_one_request(multi, target_url, dns_entry);
144 sleep(DNS_TIMEOUT + 1);
149 curl_multi_cleanup(multi);