quickjs-tart

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

lib533.c (2791B)


      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 /* used for test case 533, 534, 535 and 546 */
     25 
     26 #include "first.h"
     27 
     28 #include "memdebug.h"
     29 
     30 static CURLcode test_lib533(char *URL)
     31 {
     32   CURLcode res = CURLE_OK;
     33   CURL *curl = NULL;
     34   int running;
     35   CURLM *m = NULL;
     36   int current = 0;
     37 
     38   start_test_timing();
     39 
     40   global_init(CURL_GLOBAL_ALL);
     41 
     42   easy_init(curl);
     43 
     44   easy_setopt(curl, CURLOPT_URL, URL);
     45   easy_setopt(curl, CURLOPT_VERBOSE, 1L);
     46   easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
     47 
     48   multi_init(m);
     49 
     50   multi_add_handle(m, curl);
     51 
     52   curl_mfprintf(stderr, "Start at URL 0\n");
     53 
     54   for(;;) {
     55     struct timeval interval;
     56     fd_set rd, wr, exc;
     57     int maxfd = -99;
     58 
     59     interval.tv_sec = 1;
     60     interval.tv_usec = 0;
     61 
     62     multi_perform(m, &running);
     63 
     64     abort_on_test_timeout();
     65 
     66     if(!running) {
     67       if(!current++) {
     68         curl_mfprintf(stderr, "Advancing to URL 1\n");
     69         /* remove the handle we use */
     70         curl_multi_remove_handle(m, curl);
     71 
     72         /* make us reuse the same handle all the time, and try resetting
     73            the handle first too */
     74         curl_easy_reset(curl);
     75         easy_setopt(curl, CURLOPT_URL, libtest_arg2);
     76         easy_setopt(curl, CURLOPT_VERBOSE, 1L);
     77         easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
     78 
     79         /* re-add it */
     80         multi_add_handle(m, curl);
     81       }
     82       else
     83         break; /* done */
     84     }
     85 
     86     FD_ZERO(&rd);
     87     FD_ZERO(&wr);
     88     FD_ZERO(&exc);
     89 
     90     multi_fdset(m, &rd, &wr, &exc, &maxfd);
     91 
     92     /* At this point, maxfd is guaranteed to be greater or equal than -1. */
     93 
     94     select_test(maxfd + 1, &rd, &wr, &exc, &interval);
     95 
     96     abort_on_test_timeout();
     97   }
     98 
     99 test_cleanup:
    100 
    101   /* undocumented cleanup sequence - type UB */
    102 
    103   curl_easy_cleanup(curl);
    104   curl_multi_cleanup(m);
    105   curl_global_cleanup();
    106 
    107   return res;
    108 }