lib597.c (3186B)
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 "first.h" 25 26 #include "memdebug.h" 27 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 37 static CURLcode test_lib597(char *URL) 38 { 39 CURL *easy = NULL; 40 CURLM *multi = NULL; 41 CURLcode res = CURLE_OK; 42 int running; 43 int msgs_left; 44 CURLMsg *msg; 45 46 start_test_timing(); 47 48 global_init(CURL_GLOBAL_ALL); 49 50 easy_init(easy); 51 52 multi_init(multi); 53 54 /* go verbose */ 55 easy_setopt(easy, CURLOPT_VERBOSE, 1L); 56 57 /* specify target */ 58 easy_setopt(easy, CURLOPT_URL, URL); 59 60 easy_setopt(easy, CURLOPT_CONNECT_ONLY, 1L); 61 62 multi_add_handle(multi, easy); 63 64 for(;;) { 65 struct timeval interval; 66 fd_set fdread; 67 fd_set fdwrite; 68 fd_set fdexcep; 69 long timeout = -99; 70 int maxfd = -99; 71 72 multi_perform(multi, &running); 73 74 abort_on_test_timeout(); 75 76 if(!running) 77 break; /* done */ 78 79 FD_ZERO(&fdread); 80 FD_ZERO(&fdwrite); 81 FD_ZERO(&fdexcep); 82 83 multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd); 84 85 /* At this point, maxfd is guaranteed to be greater or equal than -1. */ 86 87 multi_timeout(multi, &timeout); 88 89 /* At this point, timeout is guaranteed to be greater or equal than 90 -1. */ 91 92 if(timeout != -1L) { 93 int itimeout; 94 #if LONG_MAX > INT_MAX 95 itimeout = (timeout > (long)INT_MAX) ? INT_MAX : (int)timeout; 96 #else 97 itimeout = (int)timeout; 98 #endif 99 interval.tv_sec = itimeout/1000; 100 interval.tv_usec = (itimeout%1000)*1000; 101 } 102 else { 103 interval.tv_sec = TEST_HANG_TIMEOUT/1000 - 1; 104 interval.tv_usec = 0; 105 } 106 107 select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &interval); 108 109 abort_on_test_timeout(); 110 } 111 112 msg = curl_multi_info_read(multi, &msgs_left); 113 if(msg) 114 res = msg->data.result; 115 116 multi_remove_handle(multi, easy); 117 118 test_cleanup: 119 120 /* undocumented cleanup sequence - type UA */ 121 122 curl_multi_cleanup(multi); 123 curl_easy_cleanup(easy); 124 curl_global_cleanup(); 125 126 return res; 127 }