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 http://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 #define _MPRINTF_REPLACE
43 #include <curl/mprintf.h>
45 static int debug_callback(CURL *curl, curl_infotype info, char *msg, size_t len, void *ptr)
50 if(info == CURLINFO_TEXT)
51 fprintf(stderr, "debug: %.*s", (int) len, msg);
56 static int do_one_request(CURLM *m, char *URL, char *resolve)
59 struct curl_slist *resolve_list = NULL;
65 resolve_list = curl_slist_append(resolve_list, resolve);
69 easy_setopt(curls, CURLOPT_URL, URL);
70 easy_setopt(curls, CURLOPT_RESOLVE, resolve_list);
71 easy_setopt(curls, CURLOPT_DEBUGFUNCTION, debug_callback);
72 easy_setopt(curls, CURLOPT_VERBOSE, 1);
73 easy_setopt(curls, CURLOPT_DNS_CACHE_TIMEOUT, DNS_TIMEOUT);
75 multi_add_handle(m, curls);
76 multi_perform(m, &still_running);
78 abort_on_test_timeout();
80 while(still_running) {
81 struct timeval timeout;
82 fd_set fdread, fdwrite, fdexcep;
91 multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
92 select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
94 abort_on_test_timeout();
95 multi_perform(m, &still_running);
97 abort_on_test_timeout();
100 while((msg = curl_multi_info_read(m, &msgs_left))) {
101 if(msg->msg == CURLMSG_DONE && msg->easy_handle == curls) {
102 res = msg->data.result;
109 curl_multi_remove_handle(m, curls);
110 curl_easy_cleanup(curls);
111 curl_slist_free_all(resolve_list);
120 char *address = libtest_arg2;
121 char *port = libtest_arg3;
127 snprintf(dns_entry, sizeof(dns_entry), "testserver.example.com:%s:%s", port, address);
131 global_init(CURL_GLOBAL_ALL);
134 for(i = 1; i <= count; i++) {
135 char target_url[256];
136 snprintf(target_url, sizeof(target_url), "http://testserver.example.com:%s%s%04d", port, path, i);
138 /* second request must succeed like the first one */
139 if((res = do_one_request(multi, target_url, dns_entry)))
143 sleep(DNS_TIMEOUT + 1);
148 curl_multi_cleanup(multi);