lib1555.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /***************************************************************************
  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. /*
  25. * Verify that some API functions are locked from being called inside callback
  26. */
  27. #include "test.h"
  28. #include "memdebug.h"
  29. static CURL *curl;
  30. static int progressCallback(void *arg,
  31. double dltotal,
  32. double dlnow,
  33. double ultotal,
  34. double ulnow)
  35. {
  36. CURLcode res = CURLE_OK;
  37. char buffer[256];
  38. size_t n = 0;
  39. (void)arg;
  40. (void)dltotal;
  41. (void)dlnow;
  42. (void)ultotal;
  43. (void)ulnow;
  44. res = curl_easy_recv(curl, buffer, 256, &n);
  45. printf("curl_easy_recv returned %d\n", res);
  46. res = curl_easy_send(curl, buffer, n, &n);
  47. printf("curl_easy_send returned %d\n", res);
  48. return 1;
  49. }
  50. int test(char *URL)
  51. {
  52. int res = 0;
  53. global_init(CURL_GLOBAL_ALL);
  54. easy_init(curl);
  55. easy_setopt(curl, CURLOPT_URL, URL);
  56. easy_setopt(curl, CURLOPT_TIMEOUT, (long)7);
  57. easy_setopt(curl, CURLOPT_NOSIGNAL, (long)1);
  58. easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progressCallback);
  59. easy_setopt(curl, CURLOPT_PROGRESSDATA, NULL);
  60. easy_setopt(curl, CURLOPT_NOPROGRESS, (long)0);
  61. res = curl_easy_perform(curl);
  62. test_cleanup:
  63. /* undocumented cleanup sequence - type UA */
  64. curl_easy_cleanup(curl);
  65. curl_global_cleanup();
  66. return res;
  67. }