Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/curl/tests/libtest/lib1515.c
2649 views
1
/***************************************************************************
2
* _ _ ____ _
3
* Project ___| | | | _ \| |
4
* / __| | | | |_) | |
5
* | (__| |_| | _ <| |___
6
* \___|\___/|_| \_\_____|
7
*
8
* Copyright (C) Daniel Stenberg, <[email protected]>, 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
25
/*
26
* Check for bugs #1303 and #1327: libcurl should never remove DNS entries
27
* created via CURLOPT_RESOLVE, neither after DNS_CACHE_TIMEOUT elapses
28
* (test1515) nor a dead connection is detected (test1616).
29
*/
30
31
#include "first.h"
32
33
#include "testtrace.h"
34
#include "memdebug.h"
35
36
#define DNS_TIMEOUT 1L
37
38
static CURLcode do_one_request(CURLM *multi, const char *URL,
39
const char *resolve)
40
{
41
CURL *curl;
42
struct curl_slist *resolve_list = NULL;
43
int still_running;
44
CURLcode res = CURLE_OK;
45
CURLMsg *msg;
46
int msgs_left;
47
48
resolve_list = curl_slist_append(resolve_list, resolve);
49
50
easy_init(curl);
51
52
easy_setopt(curl, CURLOPT_URL, URL);
53
easy_setopt(curl, CURLOPT_RESOLVE, resolve_list);
54
easy_setopt(curl, CURLOPT_DNS_CACHE_TIMEOUT, DNS_TIMEOUT);
55
56
debug_config.nohex = TRUE;
57
debug_config.tracetime = TRUE;
58
easy_setopt(curl, CURLOPT_DEBUGDATA, &debug_config);
59
easy_setopt(curl, CURLOPT_DEBUGFUNCTION, libtest_debug_cb);
60
easy_setopt(curl, CURLOPT_VERBOSE, 1L);
61
62
multi_add_handle(multi, curl);
63
multi_perform(multi, &still_running);
64
65
abort_on_test_timeout();
66
67
while(still_running) {
68
struct timeval timeout;
69
fd_set fdread, fdwrite, fdexcep;
70
int maxfd = -99;
71
72
FD_ZERO(&fdread);
73
FD_ZERO(&fdwrite);
74
FD_ZERO(&fdexcep);
75
timeout.tv_sec = 1;
76
timeout.tv_usec = 0;
77
78
multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
79
select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
80
81
abort_on_test_timeout();
82
multi_perform(multi, &still_running);
83
84
abort_on_test_timeout();
85
}
86
87
do {
88
msg = curl_multi_info_read(multi, &msgs_left);
89
if(msg && msg->msg == CURLMSG_DONE && msg->easy_handle == curl) {
90
res = msg->data.result;
91
break;
92
}
93
} while(msg);
94
95
test_cleanup:
96
97
curl_multi_remove_handle(multi, curl);
98
curl_easy_cleanup(curl);
99
curl_slist_free_all(resolve_list);
100
101
return res;
102
}
103
104
static CURLcode test_lib1515(const char *URL)
105
{
106
CURLM *multi = NULL;
107
CURLcode res = CURLE_OK;
108
const char *path = URL;
109
const char *address = libtest_arg2;
110
const char *port = libtest_arg3;
111
char dns_entry[256];
112
int i;
113
int count = 2;
114
115
curl_msnprintf(dns_entry, sizeof(dns_entry), "testserver.example.com:%s:%s",
116
port, address);
117
118
start_test_timing();
119
120
global_init(CURL_GLOBAL_ALL);
121
curl_global_trace("all");
122
multi_init(multi);
123
124
for(i = 1; i <= count; i++) {
125
char target_url[256];
126
curl_msnprintf(target_url, sizeof(target_url),
127
"http://testserver.example.com:%s/%s%04d", port, path, i);
128
129
/* second request must succeed like the first one */
130
res = do_one_request(multi, target_url, dns_entry);
131
if(res != CURLE_OK) {
132
curl_mfprintf(stderr, "request %s failed with %d\n", target_url, res);
133
goto test_cleanup;
134
}
135
136
if(i < count)
137
curlx_wait_ms((DNS_TIMEOUT + 1) * 1000);
138
}
139
140
test_cleanup:
141
142
curl_multi_cleanup(multi);
143
curl_global_cleanup();
144
145
return res;
146
}
147
148