quickjs-tart

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

lib573.c (2881B)


      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 #include "first.h"
     25 
     26 #include "testtrace.h"
     27 #include "memdebug.h"
     28 
     29 /*
     30  * Get a single URL without select().
     31  */
     32 
     33 static CURLcode test_lib573(char *URL)
     34 {
     35   CURL *c = NULL;
     36   CURLM *m = NULL;
     37   CURLcode res = CURLE_OK;
     38   int running = 1;
     39   double connect_time = 0.0;
     40   double dbl_epsilon;
     41 
     42   dbl_epsilon = 1.0;
     43   do {
     44     dbl_epsilon /= 2.0;
     45   } while((double)(1.0 + (dbl_epsilon/2.0)) > (double)1.0);
     46 
     47   start_test_timing();
     48 
     49   global_init(CURL_GLOBAL_ALL);
     50 
     51   easy_init(c);
     52 
     53   easy_setopt(c, CURLOPT_HEADER, 1L);
     54   easy_setopt(c, CURLOPT_URL, URL);
     55 
     56   libtest_debug_config.nohex = 1;
     57   libtest_debug_config.tracetime = 1;
     58   easy_setopt(c, CURLOPT_DEBUGDATA, &libtest_debug_config);
     59   easy_setopt(c, CURLOPT_DEBUGFUNCTION, libtest_debug_cb);
     60   easy_setopt(c, CURLOPT_VERBOSE, 1L);
     61 
     62   multi_init(m);
     63 
     64   multi_add_handle(m, c);
     65 
     66   while(running) {
     67     struct timeval timeout;
     68     fd_set fdread, fdwrite, fdexcep;
     69     int maxfd = -99;
     70 
     71     timeout.tv_sec = 0;
     72     timeout.tv_usec = 100000L; /* 100 ms */
     73 
     74     multi_perform(m, &running);
     75 
     76     abort_on_test_timeout();
     77 
     78     if(!running)
     79       break; /* done */
     80 
     81     FD_ZERO(&fdread);
     82     FD_ZERO(&fdwrite);
     83     FD_ZERO(&fdexcep);
     84 
     85     multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
     86 
     87     /* At this point, maxfd is guaranteed to be greater or equal than -1. */
     88 
     89     select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
     90 
     91     abort_on_test_timeout();
     92   }
     93 
     94   curl_easy_getinfo(c, CURLINFO_CONNECT_TIME, &connect_time);
     95   if(connect_time < dbl_epsilon) {
     96     curl_mfprintf(stderr, "connect time %e is < epsilon %e\n",
     97                   connect_time, dbl_epsilon);
     98     res = TEST_ERR_MAJOR_BAD;
     99   }
    100 
    101 test_cleanup:
    102 
    103   /* proper cleanup sequence - type PA */
    104 
    105   curl_multi_remove_handle(m, c);
    106   curl_multi_cleanup(m);
    107   curl_easy_cleanup(c);
    108   curl_global_cleanup();
    109 
    110   return res;
    111 }