blob: d63a58fe96b6fcc54f60629991a16071ee4d0cd7 [file] [log] [blame]
xf.li6c8fc1e2023-08-12 00:11:09 -07001/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) 1998 - 2022, 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 "test.h"
25
26/* test case and code based on https://github.com/curl/curl/issues/3927 */
27
28#include "testutil.h"
29#include "warnless.h"
30#include "memdebug.h"
31
32static int dload_progress_cb(void *a, curl_off_t b, curl_off_t c,
33 curl_off_t d, curl_off_t e)
34{
35 (void)a;
36 (void)b;
37 (void)c;
38 (void)d;
39 (void)e;
40 return 0;
41}
42
43static size_t write_cb(char *d, size_t n, size_t l, void *p)
44{
45 /* take care of the data here, ignored in this example */
46 (void)d;
47 (void)p;
48 return n*l;
49}
50
51static CURLcode run(CURL *hnd, long limit, long time)
52{
53 curl_easy_setopt(hnd, CURLOPT_LOW_SPEED_LIMIT, limit);
54 curl_easy_setopt(hnd, CURLOPT_LOW_SPEED_TIME, time);
55 return curl_easy_perform(hnd);
56}
57
58int test(char *URL)
59{
60 CURLcode ret;
61 CURL *hnd;
62 char buffer[CURL_ERROR_SIZE];
63 curl_global_init(CURL_GLOBAL_ALL);
64 hnd = curl_easy_init();
65 curl_easy_setopt(hnd, CURLOPT_URL, URL);
66 curl_easy_setopt(hnd, CURLOPT_WRITEFUNCTION, write_cb);
67 curl_easy_setopt(hnd, CURLOPT_ERRORBUFFER, buffer);
68 curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 0L);
69 curl_easy_setopt(hnd, CURLOPT_XFERINFOFUNCTION, dload_progress_cb);
70
71 printf("Start: %d\n", time(NULL));
72 ret = run(hnd, 1, 2);
73 if(ret)
74 fprintf(stderr, "error %d: %s\n", ret, buffer);
75
76 ret = run(hnd, 12000, 1);
77 if(ret != CURLE_OPERATION_TIMEDOUT)
78 fprintf(stderr, "error %d: %s\n", ret, buffer);
79 else
80 ret = CURLE_OK;
81
82 printf("End: %d\n", time(NULL));
83 curl_easy_cleanup(hnd);
84 curl_global_cleanup();
85
86 return (int)ret;
87}