lib1515.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
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  * Check for bugs #1303 and #1327: libcurl should never remove DNS entries
00025  * created via CURLOPT_RESOLVE, neither after DNS_CACHE_TIMEOUT elapses
00026  * (test1515) nor a dead connection is detected (test1616).
00027  */
00028 
00029 #include "test.h"
00030 #include "testutil.h"
00031 #include "warnless.h"
00032 #include "memdebug.h"
00033 
00034 #define TEST_HANG_TIMEOUT 60 * 1000
00035 
00036 #define DNS_TIMEOUT 1
00037 
00038 #if defined(WIN32) || defined(_WIN32)
00039 #define sleep(s) Sleep(s * 1000)
00040 #endif
00041 
00042 static int debug_callback(CURL *curl, curl_infotype info, char *msg,
00043                           size_t len, void *ptr)
00044 {
00045   (void)curl;
00046   (void)ptr;
00047 
00048   if(info == CURLINFO_TEXT)
00049     fprintf(stderr, "debug: %.*s", (int) len, msg);
00050 
00051   return 0;
00052 }
00053 
00054 static int do_one_request(CURLM *m, char *URL, char *resolve)
00055 {
00056   CURL *curls;
00057   struct curl_slist *resolve_list = NULL;
00058   int still_running;
00059   int res = 0;
00060   CURLMsg *msg;
00061   int msgs_left;
00062 
00063   resolve_list = curl_slist_append(resolve_list, resolve);
00064 
00065   easy_init(curls);
00066 
00067   easy_setopt(curls, CURLOPT_URL, URL);
00068   easy_setopt(curls, CURLOPT_RESOLVE, resolve_list);
00069   easy_setopt(curls, CURLOPT_DEBUGFUNCTION, debug_callback);
00070   easy_setopt(curls, CURLOPT_VERBOSE, 1);
00071   easy_setopt(curls, CURLOPT_DNS_CACHE_TIMEOUT, DNS_TIMEOUT);
00072 
00073   multi_add_handle(m, curls);
00074   multi_perform(m, &still_running);
00075 
00076   abort_on_test_timeout();
00077 
00078   while(still_running) {
00079     struct timeval timeout;
00080     fd_set fdread, fdwrite, fdexcep;
00081     int maxfd = -99;
00082 
00083     FD_ZERO(&fdread);
00084     FD_ZERO(&fdwrite);
00085     FD_ZERO(&fdexcep);
00086     timeout.tv_sec = 1;
00087     timeout.tv_usec = 0;
00088 
00089     multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
00090     select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
00091 
00092     abort_on_test_timeout();
00093     multi_perform(m, &still_running);
00094 
00095     abort_on_test_timeout();
00096   }
00097 
00098   while((msg = curl_multi_info_read(m, &msgs_left))) {
00099     if(msg->msg == CURLMSG_DONE && msg->easy_handle == curls) {
00100       res = msg->data.result;
00101       break;
00102     }
00103   }
00104 
00105 test_cleanup:
00106 
00107   curl_multi_remove_handle(m, curls);
00108   curl_easy_cleanup(curls);
00109   curl_slist_free_all(resolve_list);
00110 
00111   return res;
00112 }
00113 
00114 int test(char *URL)
00115 {
00116   CURLM *multi = NULL;
00117   int res = 0;
00118   char *address = libtest_arg2;
00119   char *port = libtest_arg3;
00120   char *path = URL;
00121   char dns_entry[256];
00122   int i;
00123   int count = 2;
00124 
00125   snprintf(dns_entry, sizeof(dns_entry), "testserver.example.com:%s:%s",
00126            port, address);
00127 
00128   start_test_timing();
00129 
00130   global_init(CURL_GLOBAL_ALL);
00131   multi_init(multi);
00132 
00133   for(i = 1; i <= count; i++) {
00134     char target_url[256];
00135     snprintf(target_url, sizeof(target_url),
00136              "http://testserver.example.com:%s/%s%04d", port, path, i);
00137 
00138     /* second request must succeed like the first one */
00139     res = do_one_request(multi, target_url, dns_entry);
00140     if(res)
00141       goto test_cleanup;
00142 
00143     if(i < count)
00144       sleep(DNS_TIMEOUT + 1);
00145   }
00146 
00147 test_cleanup:
00148 
00149   curl_multi_cleanup(multi);
00150 
00151   return (int) res;
00152 }


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