quickjs-tart

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

lib1523.c (2492B)


      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 /* test case and code based on https://github.com/curl/curl/issues/3927 */
     27 
     28 #include "memdebug.h"
     29 
     30 static int dload_progress_cb(void *a, curl_off_t b, curl_off_t c,
     31                              curl_off_t d, curl_off_t e)
     32 {
     33   (void)a;
     34   (void)b;
     35   (void)c;
     36   (void)d;
     37   (void)e;
     38   return 0;
     39 }
     40 
     41 static size_t t1523_write_cb(char *d, size_t n, size_t l, void *p)
     42 {
     43   /* take care of the data here, ignored in this example */
     44   (void)d;
     45   (void)p;
     46   return n*l;
     47 }
     48 
     49 static CURLcode run(CURL *hnd, long limit, long time)
     50 {
     51   curl_easy_setopt(hnd, CURLOPT_LOW_SPEED_LIMIT, limit);
     52   curl_easy_setopt(hnd, CURLOPT_LOW_SPEED_TIME, time);
     53   return curl_easy_perform(hnd);
     54 }
     55 
     56 static CURLcode test_lib1523(char *URL)
     57 {
     58   CURLcode ret;
     59   CURL *hnd;
     60   char buffer[CURL_ERROR_SIZE];
     61   curl_global_init(CURL_GLOBAL_ALL);
     62   hnd = curl_easy_init();
     63   curl_easy_setopt(hnd, CURLOPT_URL, URL);
     64   curl_easy_setopt(hnd, CURLOPT_WRITEFUNCTION, t1523_write_cb);
     65   curl_easy_setopt(hnd, CURLOPT_ERRORBUFFER, buffer);
     66   curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 0L);
     67   curl_easy_setopt(hnd, CURLOPT_XFERINFOFUNCTION, dload_progress_cb);
     68 
     69   ret = run(hnd, 1, 2);
     70   if(ret)
     71     curl_mfprintf(stderr, "error (%d) %s\n", ret, buffer);
     72 
     73   ret = run(hnd, 12000, 1);
     74   if(ret != CURLE_OPERATION_TIMEDOUT)
     75     curl_mfprintf(stderr, "error (%d) %s\n", ret, buffer);
     76   else
     77     ret = CURLE_OK;
     78 
     79   curl_easy_cleanup(hnd);
     80   curl_global_cleanup();
     81 
     82   return ret;
     83 }