/***************************************************************************1* _ _ ____ _2* Project ___| | | | _ \| |3* / __| | | | |_) | |4* | (__| |_| | _ <| |___5* \___|\___/|_| \_\_____|6*7* Copyright (C) Daniel Stenberg, <[email protected]>, et al.8*9* This software is licensed as described in the file COPYING, which10* you should have received as part of this distribution. The terms11* are also available at https://curl.se/docs/copyright.html.12*13* You may opt to use, copy, modify, merge, publish, distribute and/or sell14* copies of the Software, and permit persons to whom the Software is15* furnished to do so, under the terms of the COPYING file.16*17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY18* KIND, either express or implied.19*20* SPDX-License-Identifier: curl21*22***************************************************************************/23#include "test.h"2425/* test case and code based on https://github.com/curl/curl/issues/3927 */2627#include "testutil.h"28#include "warnless.h"29#include "memdebug.h"3031static int dload_progress_cb(void *a, curl_off_t b, curl_off_t c,32curl_off_t d, curl_off_t e)33{34(void)a;35(void)b;36(void)c;37(void)d;38(void)e;39return 0;40}4142static size_t write_cb(char *d, size_t n, size_t l, void *p)43{44/* take care of the data here, ignored in this example */45(void)d;46(void)p;47return n*l;48}4950static CURLcode run(CURL *hnd, long limit, long time)51{52curl_easy_setopt(hnd, CURLOPT_LOW_SPEED_LIMIT, limit);53curl_easy_setopt(hnd, CURLOPT_LOW_SPEED_TIME, time);54return curl_easy_perform(hnd);55}5657CURLcode test(char *URL)58{59CURLcode ret;60CURL *hnd;61char buffer[CURL_ERROR_SIZE];62curl_global_init(CURL_GLOBAL_ALL);63hnd = curl_easy_init();64curl_easy_setopt(hnd, CURLOPT_URL, URL);65curl_easy_setopt(hnd, CURLOPT_WRITEFUNCTION, write_cb);66curl_easy_setopt(hnd, CURLOPT_ERRORBUFFER, buffer);67curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 0L);68curl_easy_setopt(hnd, CURLOPT_XFERINFOFUNCTION, dload_progress_cb);6970ret = run(hnd, 1, 2);71if(ret)72curl_mfprintf(stderr, "error (%d) %s\n", ret, buffer);7374ret = run(hnd, 12000, 1);75if(ret != CURLE_OPERATION_TIMEDOUT)76curl_mfprintf(stderr, "error (%d) %s\n", ret, buffer);77else78ret = CURLE_OK;7980curl_easy_cleanup(hnd);81curl_global_cleanup();8283return ret;84}858687