lib1553.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2020, 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. ***************************************************************************/
  22. #include "test.h"
  23. #include "testutil.h"
  24. #include "warnless.h"
  25. #include "memdebug.h"
  26. #define TEST_HANG_TIMEOUT 60 * 1000
  27. static int xferinfo(void *p,
  28. curl_off_t dltotal, curl_off_t dlnow,
  29. curl_off_t ultotal, curl_off_t ulnow)
  30. {
  31. (void)p;
  32. (void)dlnow;
  33. (void)dltotal;
  34. (void)ulnow;
  35. (void)ultotal;
  36. fprintf(stderr, "xferinfo fail!\n");
  37. return 1; /* fail as fast as we can */
  38. }
  39. int test(char *URL)
  40. {
  41. CURL *curls = NULL;
  42. CURLM *multi = NULL;
  43. int still_running;
  44. int i = 0;
  45. int res = 0;
  46. curl_mimepart *field = NULL;
  47. curl_mime *mime = NULL;
  48. int counter = 1;
  49. start_test_timing();
  50. global_init(CURL_GLOBAL_ALL);
  51. multi_init(multi);
  52. easy_init(curls);
  53. mime = curl_mime_init(curls);
  54. field = curl_mime_addpart(mime);
  55. curl_mime_name(field, "name");
  56. curl_mime_data(field, "value", CURL_ZERO_TERMINATED);
  57. easy_setopt(curls, CURLOPT_URL, URL);
  58. easy_setopt(curls, CURLOPT_HEADER, 1L);
  59. easy_setopt(curls, CURLOPT_VERBOSE, 1L);
  60. easy_setopt(curls, CURLOPT_MIMEPOST, mime);
  61. easy_setopt(curls, CURLOPT_USERPWD, "u:s");
  62. easy_setopt(curls, CURLOPT_XFERINFOFUNCTION, xferinfo);
  63. easy_setopt(curls, CURLOPT_NOPROGRESS, 1L);
  64. multi_add_handle(multi, curls);
  65. multi_perform(multi, &still_running);
  66. abort_on_test_timeout();
  67. while(still_running && counter--) {
  68. int num;
  69. res = curl_multi_wait(multi, NULL, 0, TEST_HANG_TIMEOUT, &num);
  70. if(res != CURLM_OK) {
  71. printf("curl_multi_wait() returned %d\n", res);
  72. res = TEST_ERR_MAJOR_BAD;
  73. goto test_cleanup;
  74. }
  75. abort_on_test_timeout();
  76. multi_perform(multi, &still_running);
  77. abort_on_test_timeout();
  78. }
  79. test_cleanup:
  80. curl_mime_free(mime);
  81. curl_multi_remove_handle(multi, curls);
  82. curl_multi_cleanup(multi);
  83. curl_easy_cleanup(curls);
  84. curl_global_cleanup();
  85. if(res)
  86. i = res;
  87. return i; /* return the final return code */
  88. }