quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

lib1515.c (3951B)


      1 /***************************************************************************
      2  *                                  _   _ ____  _
      3  *  Project                     ___| | | |  _ \| |
      4  *                             / __| | | | |_) | |
      5  *                            | (__| |_| |  _ <| |___
      6  *                             \___|\___/|_| \_\_____|
      7  *
      8  * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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 *m, char *URL, char *resolve)
     39 {
     40   CURL *curls;
     41   struct curl_slist *resolve_list = NULL;
     42   int still_running;
     43   CURLcode res = CURLE_OK;
     44   CURLMsg *msg;
     45   int msgs_left;
     46 
     47   resolve_list = curl_slist_append(resolve_list, resolve);
     48 
     49   easy_init(curls);
     50 
     51   easy_setopt(curls, CURLOPT_URL, URL);
     52   easy_setopt(curls, CURLOPT_RESOLVE, resolve_list);
     53   easy_setopt(curls, CURLOPT_DNS_CACHE_TIMEOUT, DNS_TIMEOUT);
     54 
     55   libtest_debug_config.nohex = 1;
     56   libtest_debug_config.tracetime = 1;
     57   easy_setopt(curls, CURLOPT_DEBUGDATA, &libtest_debug_config);
     58   easy_setopt(curls, CURLOPT_DEBUGFUNCTION, libtest_debug_cb);
     59   easy_setopt(curls, CURLOPT_VERBOSE, 1L);
     60 
     61   multi_add_handle(m, curls);
     62   multi_perform(m, &still_running);
     63 
     64   abort_on_test_timeout();
     65 
     66   while(still_running) {
     67     struct timeval timeout;
     68     fd_set fdread, fdwrite, fdexcep;
     69     int maxfd = -99;
     70 
     71     FD_ZERO(&fdread);
     72     FD_ZERO(&fdwrite);
     73     FD_ZERO(&fdexcep);
     74     timeout.tv_sec = 1;
     75     timeout.tv_usec = 0;
     76 
     77     multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
     78     select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
     79 
     80     abort_on_test_timeout();
     81     multi_perform(m, &still_running);
     82 
     83     abort_on_test_timeout();
     84   }
     85 
     86   do {
     87     msg = curl_multi_info_read(m, &msgs_left);
     88     if(msg && msg->msg == CURLMSG_DONE && msg->easy_handle == curls) {
     89       res = msg->data.result;
     90       break;
     91     }
     92   } while(msg);
     93 
     94 test_cleanup:
     95 
     96   curl_multi_remove_handle(m, curls);
     97   curl_easy_cleanup(curls);
     98   curl_slist_free_all(resolve_list);
     99 
    100   return res;
    101 }
    102 
    103 static CURLcode test_lib1515(char *URL)
    104 {
    105   CURLM *multi = NULL;
    106   CURLcode res = CURLE_OK;
    107   char *address = libtest_arg2;
    108   char *port = libtest_arg3;
    109   char *path = URL;
    110   char dns_entry[256];
    111   int i;
    112   int count = 2;
    113 
    114   curl_msnprintf(dns_entry, sizeof(dns_entry), "testserver.example.com:%s:%s",
    115                  port, address);
    116 
    117   start_test_timing();
    118 
    119   global_init(CURL_GLOBAL_ALL);
    120   curl_global_trace("all");
    121   multi_init(multi);
    122 
    123   for(i = 1; i <= count; i++) {
    124     char target_url[256];
    125     curl_msnprintf(target_url, sizeof(target_url),
    126                    "http://testserver.example.com:%s/%s%04d", port, path, i);
    127 
    128     /* second request must succeed like the first one */
    129     res = do_one_request(multi, target_url, dns_entry);
    130     if(res != CURLE_OK) {
    131       curl_mfprintf(stderr, "request %s failed with %d\n", target_url, res);
    132       goto test_cleanup;
    133     }
    134 
    135     if(i < count)
    136       curlx_wait_ms((DNS_TIMEOUT + 1) * 1000);
    137   }
    138 
    139 test_cleanup:
    140 
    141   curl_multi_cleanup(multi);
    142   curl_global_cleanup();
    143 
    144   return res;
    145 }