lib597.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2017, 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.haxx.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. * - transfer some files with re-using the connection (omitted in test case)
  32. * - Disconnect from FTP server with sending QUIT command
  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. enum {
  39. CONNECT_ONLY_PHASE = 0,
  40. QUIT_PHASE,
  41. LAST_PHASE
  42. };
  43. int test(char *URL)
  44. {
  45. CURL *easy = NULL;
  46. CURLM *multi = NULL;
  47. int res = 0;
  48. int running;
  49. int msgs_left;
  50. int phase;
  51. CURLMsg *msg;
  52. start_test_timing();
  53. global_init(CURL_GLOBAL_ALL);
  54. easy_init(easy);
  55. multi_init(multi);
  56. for(phase = CONNECT_ONLY_PHASE; phase < LAST_PHASE; ++phase) {
  57. /* go verbose */
  58. easy_setopt(easy, CURLOPT_VERBOSE, 1L);
  59. /* specify target */
  60. easy_setopt(easy, CURLOPT_URL, URL);
  61. /* enable 'CONNECT_ONLY' option when in connect phase */
  62. if(phase == CONNECT_ONLY_PHASE)
  63. easy_setopt(easy, CURLOPT_CONNECT_ONLY, 1L);
  64. /* enable 'NOBODY' option to send 'QUIT' command in quit phase */
  65. if(phase == QUIT_PHASE) {
  66. easy_setopt(easy, CURLOPT_CONNECT_ONLY, 0L);
  67. easy_setopt(easy, CURLOPT_NOBODY, 1L);
  68. easy_setopt(easy, CURLOPT_FORBID_REUSE, 1L);
  69. }
  70. multi_add_handle(multi, easy);
  71. for(;;) {
  72. struct timeval interval;
  73. fd_set fdread;
  74. fd_set fdwrite;
  75. fd_set fdexcep;
  76. long timeout = -99;
  77. int maxfd = -99;
  78. multi_perform(multi, &running);
  79. abort_on_test_timeout();
  80. if(!running)
  81. break; /* done */
  82. FD_ZERO(&fdread);
  83. FD_ZERO(&fdwrite);
  84. FD_ZERO(&fdexcep);
  85. multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
  86. /* At this point, maxfd is guaranteed to be greater or equal than -1. */
  87. multi_timeout(multi, &timeout);
  88. /* At this point, timeout is guaranteed to be greater or equal than
  89. -1. */
  90. if(timeout != -1L) {
  91. int itimeout = (timeout > (long)INT_MAX) ? INT_MAX : (int)timeout;
  92. interval.tv_sec = itimeout/1000;
  93. interval.tv_usec = (itimeout%1000)*1000;
  94. }
  95. else {
  96. interval.tv_sec = TEST_HANG_TIMEOUT/1000 + 1;
  97. interval.tv_usec = 0;
  98. }
  99. select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &interval);
  100. abort_on_test_timeout();
  101. }
  102. msg = curl_multi_info_read(multi, &msgs_left);
  103. if(msg)
  104. res = msg->data.result;
  105. multi_remove_handle(multi, easy);
  106. }
  107. test_cleanup:
  108. /* undocumented cleanup sequence - type UA */
  109. curl_multi_cleanup(multi);
  110. curl_easy_cleanup(easy);
  111. curl_global_cleanup();
  112. return res;
  113. }