2013-08-08 19:01:16 +08:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2018-11-22 16:01:24 +08:00
|
|
|
* Copyright (C) 2013 - 2018, Linus Nielsen Feltzing <linus@haxx.se>
|
2013-08-08 19:01:16 +08:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2016-02-03 07:19:02 +08:00
|
|
|
* are also available at https://curl.haxx.se/docs/copyright.html.
|
2013-08-08 19:01:16 +08:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use global DNS cache (while deprecated it should still work), populate it
|
|
|
|
* with CURLOPT_RESOLVE in the first request and then make sure a subsequent
|
|
|
|
* easy transfer finds and uses the populated stuff.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "test.h"
|
|
|
|
|
|
|
|
#include "memdebug.h"
|
|
|
|
|
|
|
|
#define NUM_HANDLES 2
|
|
|
|
|
|
|
|
int test(char *URL)
|
|
|
|
{
|
2013-09-03 03:39:53 +08:00
|
|
|
int res = 0;
|
2013-08-08 19:01:16 +08:00
|
|
|
CURL *curl[NUM_HANDLES] = {NULL, NULL};
|
|
|
|
char *port = libtest_arg3;
|
|
|
|
char *address = libtest_arg2;
|
|
|
|
char dnsentry[256];
|
|
|
|
struct curl_slist *slist = NULL;
|
|
|
|
int i;
|
|
|
|
char target_url[256];
|
|
|
|
(void)URL; /* URL is setup in the code */
|
|
|
|
|
2013-09-03 03:39:53 +08:00
|
|
|
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
|
2013-08-08 19:01:16 +08:00
|
|
|
fprintf(stderr, "curl_global_init() failed\n");
|
|
|
|
return TEST_ERR_MAJOR_BAD;
|
|
|
|
}
|
|
|
|
|
2018-11-22 16:01:24 +08:00
|
|
|
msnprintf(dnsentry, sizeof(dnsentry), "server.example.curl:%s:%s",
|
|
|
|
port, address);
|
2013-08-08 19:01:16 +08:00
|
|
|
printf("%s\n", dnsentry);
|
|
|
|
slist = curl_slist_append(slist, dnsentry);
|
|
|
|
|
|
|
|
/* get NUM_HANDLES easy handles */
|
2017-09-10 05:09:06 +08:00
|
|
|
for(i = 0; i < NUM_HANDLES; i++) {
|
2013-08-08 19:01:16 +08:00
|
|
|
/* get an easy handle */
|
|
|
|
easy_init(curl[i]);
|
|
|
|
/* specify target */
|
2018-11-22 16:01:24 +08:00
|
|
|
msnprintf(target_url, sizeof(target_url),
|
|
|
|
"http://server.example.curl:%s/path/1512%04i",
|
|
|
|
port, i + 1);
|
2013-08-08 19:01:16 +08:00
|
|
|
target_url[sizeof(target_url) - 1] = '\0';
|
|
|
|
easy_setopt(curl[i], CURLOPT_URL, target_url);
|
|
|
|
/* go verbose */
|
|
|
|
easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
|
|
|
|
/* include headers */
|
|
|
|
easy_setopt(curl[i], CURLOPT_HEADER, 1L);
|
|
|
|
|
|
|
|
easy_setopt(curl[i], CURLOPT_DNS_USE_GLOBAL_CACHE, 1L);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make the first one populate the GLOBAL cache */
|
|
|
|
easy_setopt(curl[0], CURLOPT_RESOLVE, slist);
|
|
|
|
|
|
|
|
/* run NUM_HANDLES transfers */
|
2017-09-10 05:09:06 +08:00
|
|
|
for(i = 0; (i < NUM_HANDLES) && !res; i++)
|
2013-08-08 19:01:16 +08:00
|
|
|
res = curl_easy_perform(curl[i]);
|
|
|
|
|
|
|
|
test_cleanup:
|
|
|
|
|
|
|
|
curl_easy_cleanup(curl[0]);
|
|
|
|
curl_easy_cleanup(curl[1]);
|
|
|
|
curl_slist_free_all(slist);
|
|
|
|
curl_global_cleanup();
|
|
|
|
|
2013-09-03 03:39:53 +08:00
|
|
|
return res;
|
2013-08-08 19:01:16 +08:00
|
|
|
}
|