lib597.c 3.7 KB

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