lib597.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. #include <limits.h>
  26. #include "testutil.h"
  27. #include "warnless.h"
  28. #include "memdebug.h"
  29. #define TEST_HANG_TIMEOUT 60 * 1000
  30. /*
  31. * Test case for below scenario:
  32. * - Connect to an FTP server using CONNECT_ONLY option
  33. *
  34. * The test case originated for verifying CONNECT_ONLY option shall not
  35. * block after protocol connect is done, but it returns the message
  36. * with function curl_multi_info_read().
  37. */
  38. CURLcode test(char *URL)
  39. {
  40. CURL *easy = NULL;
  41. CURLM *multi = NULL;
  42. CURLcode res = CURLE_OK;
  43. int running;
  44. int msgs_left;
  45. CURLMsg *msg;
  46. start_test_timing();
  47. global_init(CURL_GLOBAL_ALL);
  48. easy_init(easy);
  49. multi_init(multi);
  50. /* go verbose */
  51. easy_setopt(easy, CURLOPT_VERBOSE, 1L);
  52. /* specify target */
  53. easy_setopt(easy, CURLOPT_URL, URL);
  54. easy_setopt(easy, CURLOPT_CONNECT_ONLY, 1L);
  55. multi_add_handle(multi, easy);
  56. for(;;) {
  57. struct timeval interval;
  58. fd_set fdread;
  59. fd_set fdwrite;
  60. fd_set fdexcep;
  61. long timeout = -99;
  62. int maxfd = -99;
  63. multi_perform(multi, &running);
  64. abort_on_test_timeout();
  65. if(!running)
  66. break; /* done */
  67. FD_ZERO(&fdread);
  68. FD_ZERO(&fdwrite);
  69. FD_ZERO(&fdexcep);
  70. multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
  71. /* At this point, maxfd is guaranteed to be greater or equal than -1. */
  72. multi_timeout(multi, &timeout);
  73. /* At this point, timeout is guaranteed to be greater or equal than
  74. -1. */
  75. if(timeout != -1L) {
  76. int itimeout;
  77. #if LONG_MAX > INT_MAX
  78. itimeout = (timeout > (long)INT_MAX) ? INT_MAX : (int)timeout;
  79. #else
  80. itimeout = (int)timeout;
  81. #endif
  82. interval.tv_sec = itimeout/1000;
  83. interval.tv_usec = (itimeout%1000)*1000;
  84. }
  85. else {
  86. interval.tv_sec = TEST_HANG_TIMEOUT/1000 - 1;
  87. interval.tv_usec = 0;
  88. }
  89. select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &interval);
  90. abort_on_test_timeout();
  91. }
  92. msg = curl_multi_info_read(multi, &msgs_left);
  93. if(msg)
  94. res = msg->data.result;
  95. multi_remove_handle(multi, easy);
  96. test_cleanup:
  97. /* undocumented cleanup sequence - type UA */
  98. curl_multi_cleanup(multi);
  99. curl_easy_cleanup(easy);
  100. curl_global_cleanup();
  101. return res;
  102. }