quickjs-tart

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

lib575.c (2711B)


      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 /* 3x download!
     29  * 1. normal
     30  * 2. dup handle
     31  * 3. with multi interface
     32  */
     33 
     34 static CURLcode test_lib575(char *URL)
     35 {
     36   CURL *handle = NULL;
     37   CURL *duphandle = NULL;
     38   CURLM *mhandle = NULL;
     39   CURLcode res = CURLE_OK;
     40   int still_running = 0;
     41 
     42   start_test_timing();
     43 
     44   global_init(CURL_GLOBAL_ALL);
     45 
     46   easy_init(handle);
     47 
     48   easy_setopt(handle, CURLOPT_URL, URL);
     49   easy_setopt(handle, CURLOPT_WILDCARDMATCH, 1L);
     50   easy_setopt(handle, CURLOPT_VERBOSE, 1L);
     51 
     52   res = curl_easy_perform(handle);
     53   if(res)
     54     goto test_cleanup;
     55 
     56   res = curl_easy_perform(handle);
     57   if(res)
     58     goto test_cleanup;
     59 
     60   duphandle = curl_easy_duphandle(handle);
     61   if(!duphandle)
     62     goto test_cleanup;
     63   curl_easy_cleanup(handle);
     64   handle = duphandle;
     65 
     66   multi_init(mhandle);
     67 
     68   multi_add_handle(mhandle, handle);
     69 
     70   multi_perform(mhandle, &still_running);
     71 
     72   abort_on_test_timeout();
     73 
     74   while(still_running) {
     75     struct timeval timeout;
     76     fd_set fdread;
     77     fd_set fdwrite;
     78     fd_set fdexcep;
     79     int maxfd = -99;
     80 
     81     timeout.tv_sec = 0;
     82     timeout.tv_usec = 100000L; /* 100 ms */
     83 
     84     FD_ZERO(&fdread);
     85     FD_ZERO(&fdwrite);
     86     FD_ZERO(&fdexcep);
     87 
     88     multi_fdset(mhandle, &fdread, &fdwrite, &fdexcep, &maxfd);
     89 
     90     /* At this point, maxfd is guaranteed to be greater or equal than -1. */
     91 
     92     select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
     93 
     94     abort_on_test_timeout();
     95 
     96     multi_perform(mhandle, &still_running);
     97 
     98     abort_on_test_timeout();
     99   }
    100 
    101 test_cleanup:
    102 
    103   /* undocumented cleanup sequence - type UA */
    104 
    105   curl_multi_cleanup(mhandle);
    106   curl_easy_cleanup(handle);
    107   curl_global_cleanup();
    108 
    109   return res;
    110 }