quickjs-tart

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

lib1501.c (2913B)


      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 "memdebug.h"
     27 
     28 static CURLcode test_lib1501(char *URL)
     29 {
     30   static const long HANG_TIMEOUT = 30 * 1000;
     31   /* 500 milliseconds allowed. An extreme number but lets be really
     32      conservative to allow old and slow machines to run this test too */
     33   static const int MAX_BLOCKED_TIME_MS = 500;
     34 
     35   CURL *handle = NULL;
     36   CURLM *mhandle = NULL;
     37   CURLcode res = CURLE_OK;
     38   int still_running = 0;
     39 
     40   start_test_timing();
     41 
     42   global_init(CURL_GLOBAL_ALL);
     43 
     44   easy_init(handle);
     45 
     46   easy_setopt(handle, CURLOPT_URL, URL);
     47   easy_setopt(handle, CURLOPT_VERBOSE, 1L);
     48 
     49   multi_init(mhandle);
     50 
     51   multi_add_handle(mhandle, handle);
     52 
     53   multi_perform(mhandle, &still_running);
     54 
     55   abort_on_test_timeout_custom(HANG_TIMEOUT);
     56 
     57   while(still_running) {
     58     struct timeval timeout;
     59     fd_set fdread;
     60     fd_set fdwrite;
     61     fd_set fdexcep;
     62     int maxfd = -99;
     63     struct curltime before;
     64     struct curltime after;
     65     timediff_t e;
     66 
     67     timeout.tv_sec = 0;
     68     timeout.tv_usec = 100000L; /* 100 ms */
     69 
     70     FD_ZERO(&fdread);
     71     FD_ZERO(&fdwrite);
     72     FD_ZERO(&fdexcep);
     73 
     74     multi_fdset(mhandle, &fdread, &fdwrite, &fdexcep, &maxfd);
     75 
     76     /* At this point, maxfd is guaranteed to be greater or equal than -1. */
     77 
     78     select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
     79 
     80     abort_on_test_timeout_custom(HANG_TIMEOUT);
     81 
     82     curl_mfprintf(stderr, "ping\n");
     83     before = curlx_now();
     84 
     85     multi_perform(mhandle, &still_running);
     86 
     87     abort_on_test_timeout_custom(HANG_TIMEOUT);
     88 
     89     after = curlx_now();
     90     e = curlx_timediff(after, before);
     91     curl_mfprintf(stderr, "pong = %ld\n", (long)e);
     92 
     93     if(e > MAX_BLOCKED_TIME_MS) {
     94       res = CURLE_TOO_LARGE;
     95       break;
     96     }
     97   }
     98 
     99 test_cleanup:
    100 
    101   /* undocumented cleanup sequence - type UA */
    102 
    103   curl_multi_cleanup(mhandle);
    104   curl_easy_cleanup(handle);
    105   curl_global_cleanup();
    106 
    107   return res;
    108 }