lib597.c 3.1 KB

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