quickjs-tart

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

lib2402.c (3776B)


      1 /***************************************************************************
      2  *                                  _   _ ____  _
      3  *  Project                     ___| | | |  _ \| |
      4  *                             / __| | | | |_) | |
      5  *                            | (__| |_| |  _ <| |___
      6  *                             \___|\___/|_| \_\_____|
      7  *
      8  * Copyright (C) Linus Nielsen Feltzing <linus@haxx.se>
      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_lib2402(char *URL)
     29 {
     30   CURLcode res = CURLE_OK;
     31   CURL *curl[NUM_HANDLES] = {0};
     32   int running;
     33   CURLM *m = NULL;
     34   size_t i;
     35   char target_url[256];
     36   char dnsentry[256];
     37   struct curl_slist *slist = NULL;
     38   char *port = libtest_arg3;
     39   char *address = libtest_arg2;
     40 
     41   (void)URL;
     42 
     43   curl_msnprintf(dnsentry, sizeof(dnsentry), "localhost:%s:%s",
     44                  port, address);
     45   curl_mprintf("%s\n", dnsentry);
     46   slist = curl_slist_append(slist, dnsentry);
     47   if(!slist) {
     48     curl_mfprintf(stderr, "curl_slist_append() failed\n");
     49     goto test_cleanup;
     50   }
     51 
     52   start_test_timing();
     53 
     54   global_init(CURL_GLOBAL_ALL);
     55 
     56   multi_init(m);
     57 
     58   multi_setopt(m, CURLMOPT_MAXCONNECTS, 1L);
     59 
     60   /* get each easy handle */
     61   for(i = 0; i < CURL_ARRAYSIZE(curl); i++) {
     62     /* get an easy handle */
     63     easy_init(curl[i]);
     64     /* specify target */
     65     curl_msnprintf(target_url, sizeof(target_url),
     66                    "https://localhost:%s/path/2402%04i",
     67                    port, (int)i + 1);
     68     target_url[sizeof(target_url) - 1] = '\0';
     69     easy_setopt(curl[i], CURLOPT_URL, target_url);
     70     /* go http2 */
     71     easy_setopt(curl[i], CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
     72     /* no peer verify */
     73     easy_setopt(curl[i], CURLOPT_SSL_VERIFYPEER, 0L);
     74     easy_setopt(curl[i], CURLOPT_SSL_VERIFYHOST, 0L);
     75     /* wait for first connection established to see if we can share it */
     76     easy_setopt(curl[i], CURLOPT_PIPEWAIT, 1L);
     77     /* go verbose */
     78     easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
     79     /* include headers */
     80     easy_setopt(curl[i], CURLOPT_HEADER, 1L);
     81 
     82     easy_setopt(curl[i], CURLOPT_RESOLVE, slist);
     83   }
     84 
     85   curl_mfprintf(stderr, "Start at URL 0\n");
     86 
     87   for(i = 0; i < CURL_ARRAYSIZE(curl); i++) {
     88     /* add handle to multi */
     89     multi_add_handle(m, curl[i]);
     90 
     91     for(;;) {
     92       struct timeval interval;
     93       fd_set rd, wr, exc;
     94       int maxfd = -99;
     95 
     96       interval.tv_sec = 1;
     97       interval.tv_usec = 0;
     98 
     99       multi_perform(m, &running);
    100 
    101       abort_on_test_timeout();
    102 
    103       if(!running)
    104         break; /* done */
    105 
    106       FD_ZERO(&rd);
    107       FD_ZERO(&wr);
    108       FD_ZERO(&exc);
    109 
    110       multi_fdset(m, &rd, &wr, &exc, &maxfd);
    111 
    112       /* At this point, maxfd is guaranteed to be greater or equal than -1. */
    113 
    114       select_test(maxfd + 1, &rd, &wr, &exc, &interval);
    115 
    116       abort_on_test_timeout();
    117     }
    118     curlx_wait_ms(1); /* to ensure different end times */
    119   }
    120 
    121 test_cleanup:
    122 
    123   /* proper cleanup sequence - type PB */
    124 
    125   for(i = 0; i < CURL_ARRAYSIZE(curl); i++) {
    126     curl_multi_remove_handle(m, curl[i]);
    127     curl_easy_cleanup(curl[i]);
    128   }
    129 
    130   curl_slist_free_all(slist);
    131 
    132   curl_multi_cleanup(m);
    133   curl_global_cleanup();
    134 
    135   return res;
    136 }