lib1512.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 2013 - 2016, Linus Nielsen Feltzing <linus@haxx.se>
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 
00023 /*
00024  * Use global DNS cache (while deprecated it should still work), populate it
00025  * with CURLOPT_RESOLVE in the first request and then make sure a subsequent
00026  * easy transfer finds and uses the populated stuff.
00027  */
00028 
00029 #include "test.h"
00030 
00031 #include "memdebug.h"
00032 
00033 #define NUM_HANDLES 2
00034 
00035 int test(char *URL)
00036 {
00037   int res = 0;
00038   CURL *curl[NUM_HANDLES] = {NULL, NULL};
00039   char *port = libtest_arg3;
00040   char *address = libtest_arg2;
00041   char dnsentry[256];
00042   struct curl_slist *slist = NULL;
00043   int i;
00044   char target_url[256];
00045   (void)URL; /* URL is setup in the code */
00046 
00047   if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
00048     fprintf(stderr, "curl_global_init() failed\n");
00049     return TEST_ERR_MAJOR_BAD;
00050   }
00051 
00052   snprintf(dnsentry, sizeof(dnsentry), "server.example.curl:%s:%s",
00053            port, address);
00054   printf("%s\n", dnsentry);
00055   slist = curl_slist_append(slist, dnsentry);
00056 
00057   /* get NUM_HANDLES easy handles */
00058   for(i=0; i < NUM_HANDLES; i++) {
00059     /* get an easy handle */
00060     easy_init(curl[i]);
00061     /* specify target */
00062     snprintf(target_url, sizeof(target_url),
00063              "http://server.example.curl:%s/path/1512%04i",
00064              port, i + 1);
00065     target_url[sizeof(target_url) - 1] = '\0';
00066     easy_setopt(curl[i], CURLOPT_URL, target_url);
00067     /* go verbose */
00068     easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
00069     /* include headers */
00070     easy_setopt(curl[i], CURLOPT_HEADER, 1L);
00071 
00072     easy_setopt(curl[i], CURLOPT_DNS_USE_GLOBAL_CACHE, 1L);
00073   }
00074 
00075   /* make the first one populate the GLOBAL cache */
00076   easy_setopt(curl[0], CURLOPT_RESOLVE, slist);
00077 
00078   /* run NUM_HANDLES transfers */
00079   for(i=0; (i < NUM_HANDLES) && !res; i++)
00080     res = curl_easy_perform(curl[i]);
00081 
00082 test_cleanup:
00083 
00084   curl_easy_cleanup(curl[0]);
00085   curl_easy_cleanup(curl[1]);
00086   curl_slist_free_all(slist);
00087   curl_global_cleanup();
00088 
00089   return res;
00090 }
00091 


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:05