lib591.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. /* lib591 is used for test cases 591, 592, 593 and 594 */
  24. #include <limits.h>
  25. #include <fcntl.h>
  26. #include "testutil.h"
  27. #include "warnless.h"
  28. #include "memdebug.h"
  29. #define TEST_HANG_TIMEOUT 60 * 1000
  30. int test(char *URL)
  31. {
  32. CURL *easy = NULL;
  33. CURLM *multi = NULL;
  34. int res = 0;
  35. int running;
  36. int msgs_left;
  37. CURLMsg *msg;
  38. FILE *upload = NULL;
  39. start_test_timing();
  40. upload = fopen(libtest_arg3, "rb");
  41. if(!upload) {
  42. fprintf(stderr, "fopen() failed with error: %d (%s)\n",
  43. errno, strerror(errno));
  44. fprintf(stderr, "Error opening file: (%s)\n", libtest_arg3);
  45. return TEST_ERR_FOPEN;
  46. }
  47. res_global_init(CURL_GLOBAL_ALL);
  48. if(res) {
  49. fclose(upload);
  50. return res;
  51. }
  52. easy_init(easy);
  53. /* go verbose */
  54. easy_setopt(easy, CURLOPT_VERBOSE, 1L);
  55. /* specify target */
  56. easy_setopt(easy, CURLOPT_URL, URL);
  57. /* enable uploading */
  58. easy_setopt(easy, CURLOPT_UPLOAD, 1L);
  59. /* data pointer for the file read function */
  60. easy_setopt(easy, CURLOPT_READDATA, upload);
  61. /* use active mode FTP */
  62. easy_setopt(easy, CURLOPT_FTPPORT, "-");
  63. /* server connection timeout */
  64. easy_setopt(easy, CURLOPT_ACCEPTTIMEOUT_MS,
  65. strtol(libtest_arg2, NULL, 10)*1000);
  66. multi_init(multi);
  67. multi_add_handle(multi, easy);
  68. for(;;) {
  69. struct timeval interval;
  70. fd_set fdread;
  71. fd_set fdwrite;
  72. fd_set fdexcep;
  73. long timeout = -99;
  74. int maxfd = -99;
  75. multi_perform(multi, &running);
  76. abort_on_test_timeout();
  77. if(!running)
  78. break; /* done */
  79. FD_ZERO(&fdread);
  80. FD_ZERO(&fdwrite);
  81. FD_ZERO(&fdexcep);
  82. multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
  83. /* At this point, maxfd is guaranteed to be greater or equal than -1. */
  84. multi_timeout(multi, &timeout);
  85. /* At this point, timeout is guaranteed to be greater or equal than -1. */
  86. if(timeout != -1L) {
  87. int itimeout = (timeout > (long)INT_MAX) ? INT_MAX : (int)timeout;
  88. interval.tv_sec = itimeout/1000;
  89. interval.tv_usec = (itimeout%1000)*1000;
  90. }
  91. else {
  92. interval.tv_sec = 0;
  93. interval.tv_usec = 100000L; /* 100 ms */
  94. }
  95. select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &interval);
  96. abort_on_test_timeout();
  97. }
  98. msg = curl_multi_info_read(multi, &msgs_left);
  99. if(msg)
  100. res = msg->data.result;
  101. test_cleanup:
  102. /* undocumented cleanup sequence - type UA */
  103. curl_multi_cleanup(multi);
  104. curl_easy_cleanup(easy);
  105. curl_global_cleanup();
  106. /* close the local file */
  107. fclose(upload);
  108. return res;
  109. }