lib597.c 3.8 KB

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