quickjs-tart

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

lib1506.c (3645B)


      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_lib1506(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, *slist2;
     38   char *port = libtest_arg3;
     39   char *address = libtest_arg2;
     40 
     41   (void)URL;
     42 
     43   /* Create fake DNS entries for serverX.example.com for all handles */
     44   for(i = 0; i < CURL_ARRAYSIZE(curl); i++) {
     45     curl_msnprintf(dnsentry, sizeof(dnsentry), "server%d.example.com:%s:%s",
     46                    (int)i + 1, port, address);
     47     curl_mprintf("%s\n", dnsentry);
     48     slist2 = curl_slist_append(slist, dnsentry);
     49     if(!slist2) {
     50       curl_mfprintf(stderr, "curl_slist_append() failed\n");
     51       goto test_cleanup;
     52     }
     53     slist = slist2;
     54   }
     55 
     56   start_test_timing();
     57 
     58   global_init(CURL_GLOBAL_ALL);
     59 
     60   multi_init(m);
     61 
     62   multi_setopt(m, CURLMOPT_MAXCONNECTS, 3L);
     63 
     64   /* get each easy handle */
     65   for(i = 0; i < CURL_ARRAYSIZE(curl); i++) {
     66     /* get an easy handle */
     67     easy_init(curl[i]);
     68     /* specify target */
     69     curl_msnprintf(target_url, sizeof(target_url),
     70                    "http://server%d.example.com:%s/path/1506%04i",
     71                    (int)i + 1, port, (int)i + 1);
     72     target_url[sizeof(target_url) - 1] = '\0';
     73     easy_setopt(curl[i], CURLOPT_URL, target_url);
     74     /* go verbose */
     75     easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
     76     /* include headers */
     77     easy_setopt(curl[i], CURLOPT_HEADER, 1L);
     78 
     79     easy_setopt(curl[i], CURLOPT_RESOLVE, slist);
     80   }
     81 
     82   curl_mfprintf(stderr, "Start at URL 0\n");
     83 
     84   for(i = 0; i < CURL_ARRAYSIZE(curl); i++) {
     85     /* add handle to multi */
     86     multi_add_handle(m, curl[i]);
     87 
     88     for(;;) {
     89       struct timeval interval;
     90       fd_set rd, wr, exc;
     91       int maxfd = -99;
     92 
     93       interval.tv_sec = 1;
     94       interval.tv_usec = 0;
     95 
     96       multi_perform(m, &running);
     97 
     98       abort_on_test_timeout();
     99 
    100       if(!running)
    101         break; /* done */
    102 
    103       FD_ZERO(&rd);
    104       FD_ZERO(&wr);
    105       FD_ZERO(&exc);
    106 
    107       multi_fdset(m, &rd, &wr, &exc, &maxfd);
    108 
    109       /* At this point, maxfd is guaranteed to be greater or equal than -1. */
    110 
    111       select_test(maxfd + 1, &rd, &wr, &exc, &interval);
    112 
    113       abort_on_test_timeout();
    114     }
    115     curlx_wait_ms(1); /* to ensure different end times */
    116   }
    117 
    118 test_cleanup:
    119 
    120   /* proper cleanup sequence - type PB */
    121 
    122   for(i = 0; i < CURL_ARRAYSIZE(curl); i++) {
    123     curl_multi_remove_handle(m, curl[i]);
    124     curl_easy_cleanup(curl[i]);
    125   }
    126 
    127   curl_slist_free_all(slist);
    128 
    129   curl_multi_cleanup(m);
    130   curl_global_cleanup();
    131 
    132   return res;
    133 }