1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2014, 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, size_t len, void *ptr)
47 if(info == CURLINFO_TEXT)
48 fprintf(stderr, "debug: %.*s", (int) len, msg);
53 static int do_one_request(CURLM *m, char *URL, char *resolve)
56 struct curl_slist *resolve_list = NULL;
62 resolve_list = curl_slist_append(resolve_list, resolve);
66 easy_setopt(curls, CURLOPT_URL, URL);
67 easy_setopt(curls, CURLOPT_RESOLVE, resolve_list);
68 easy_setopt(curls, CURLOPT_DEBUGFUNCTION, debug_callback);
69 easy_setopt(curls, CURLOPT_VERBOSE, 1);
70 easy_setopt(curls, CURLOPT_DNS_CACHE_TIMEOUT, DNS_TIMEOUT);
72 multi_add_handle(m, curls);
73 multi_perform(m, &still_running);
75 abort_on_test_timeout();
77 while(still_running) {
78 struct timeval timeout;
79 fd_set fdread, fdwrite, fdexcep;
88 multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
89 select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
91 abort_on_test_timeout();
92 multi_perform(m, &still_running);
94 abort_on_test_timeout();
97 while((msg = curl_multi_info_read(m, &msgs_left))) {
98 if(msg->msg == CURLMSG_DONE && msg->easy_handle == curls) {
99 res = msg->data.result;
106 curl_multi_remove_handle(m, curls);
107 curl_easy_cleanup(curls);
108 curl_slist_free_all(resolve_list);
117 char *address = libtest_arg2;
118 char *port = libtest_arg3;
124 snprintf(dns_entry, sizeof(dns_entry), "testserver.example.com:%s:%s", port, address);
128 global_init(CURL_GLOBAL_ALL);
131 for(i = 1; i <= count; i++) {
132 char target_url[256];
133 snprintf(target_url, sizeof(target_url), "http://testserver.example.com:%s/%s%04d", port, path, i);
135 /* second request must succeed like the first one */
136 if((res = do_one_request(multi, target_url, dns_entry)))
140 sleep(DNS_TIMEOUT + 1);
145 curl_multi_cleanup(multi);