2
0

lib1523.c 2.4 KB

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