lib597.c
Go to the documentation of this file.
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 
24 #ifdef HAVE_LIMITS_H
25 #include <limits.h>
26 #endif
27 
28 #include "testutil.h"
29 #include "warnless.h"
30 #include "memdebug.h"
31 
32 #define TEST_HANG_TIMEOUT 5 * 1000
33 
34 /*
35  * Test case for below scenario:
36  * - Connect to an FTP server using CONNECT_ONLY option
37  * - transfer some files with re-using the connection (omitted in test case)
38  * - Disconnect from FTP server with sending QUIT command
39  *
40  * The test case originated for verifying CONNECT_ONLY option shall not
41  * block after protocol connect is done, but it returns the message
42  * with function curl_multi_info_read().
43  */
44 
45 enum {
49 };
50 
51 int test(char *URL)
52 {
53  CURL *easy = NULL;
54  CURLM *multi = NULL;
55  int res = 0;
56  int running;
57  int msgs_left;
58  int phase;
59  CURLMsg *msg;
60 
62 
64 
65  easy_init(easy);
66 
67  multi_init(multi);
68 
69  for(phase = CONNECT_ONLY_PHASE; phase < LAST_PHASE; ++phase) {
70  /* go verbose */
71  easy_setopt(easy, CURLOPT_VERBOSE, 1L);
72 
73  /* specify target */
74  easy_setopt(easy, CURLOPT_URL, URL);
75 
76  /* enable 'CONNECT_ONLY' option when in connect phase */
77  if(phase == CONNECT_ONLY_PHASE)
78  easy_setopt(easy, CURLOPT_CONNECT_ONLY, 1L);
79 
80  /* enable 'NOBODY' option to send 'QUIT' command in quit phase */
81  if(phase == QUIT_PHASE) {
82  easy_setopt(easy, CURLOPT_CONNECT_ONLY, 0L);
83  easy_setopt(easy, CURLOPT_NOBODY, 1L);
84  easy_setopt(easy, CURLOPT_FORBID_REUSE, 1L);
85  }
86 
87  multi_add_handle(multi, easy);
88 
89  for(;;) {
90  struct timeval interval;
91  fd_set fdread;
92  fd_set fdwrite;
93  fd_set fdexcep;
94  long timeout = -99;
95  int maxfd = -99;
96 
97  multi_perform(multi, &running);
98 
100 
101  if(!running)
102  break; /* done */
103 
104  FD_ZERO(&fdread);
105  FD_ZERO(&fdwrite);
106  FD_ZERO(&fdexcep);
107 
108  multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
109 
110  /* At this point, maxfd is guaranteed to be greater or equal than -1. */
111 
112  multi_timeout(multi, &timeout);
113 
114  /* At this point, timeout is guaranteed to be greater or equal than
115  -1. */
116 
117  if(timeout != -1L) {
118  int itimeout = (timeout > (long)INT_MAX) ? INT_MAX : (int)timeout;
119  interval.tv_sec = itimeout/1000;
120  interval.tv_usec = (itimeout%1000)*1000;
121  }
122  else {
123  interval.tv_sec = TEST_HANG_TIMEOUT/1000 + 1;
124  interval.tv_usec = 0;
125  }
126 
127  select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &interval);
128 
130  }
131 
132  msg = curl_multi_info_read(multi, &msgs_left);
133  if(msg)
134  res = msg->data.result;
135 
136  multi_remove_handle(multi, easy);
137  }
138 
139 test_cleanup:
140 
141  /* undocumented cleanup sequence - type UA */
142 
143  curl_multi_cleanup(multi);
144  curl_easy_cleanup(easy);
146 
147  return res;
148 }
#define select_test(A, B, C, D, E)
Definition: test.h:378
#define global_init(A)
Definition: test.h:431
#define easy_setopt(A, B, C)
Definition: test.h:190
uv_timer_t timeout
Definition: multi-uv.c:42
#define multi_add_handle(A, B)
Definition: test.h:238
Definition: multi.h:93
static int res
#define abort_on_test_timeout()
Definition: test.h:404
#define TEST_HANG_TIMEOUT
Definition: lib597.c:32
int test(char *URL)
Definition: lib597.c:51
#define easy_init(A)
Definition: test.h:145
#define multi_fdset(A, B, C, D, E)
Definition: test.h:323
CURL_EXTERN void curl_easy_cleanup(CURL *curl)
#define multi_remove_handle(A, B)
Definition: test.h:263
#define multi_perform(A, B)
Definition: test.h:293
#define multi_init(A)
Definition: test.h:166
void CURLM
Definition: multi.h:58
void CURL
Definition: curl.h:102
CURL_EXTERN CURLMsg * curl_multi_info_read(CURLM *multi_handle, int *msgs_in_queue)
union CURLMsg::@6 data
static CURL * easy[MAX_EASY_HANDLES]
CURL_EXTERN void curl_global_cleanup(void)
curl_global_cleanup() globally cleanups curl, uses the value of "init_flags" to determine what needs ...
Definition: easy.c:312
#define CURL_GLOBAL_ALL
Definition: curl.h:2519
CURLcode result
Definition: multi.h:98
#define start_test_timing()
Definition: test.h:383
CURL_EXTERN CURLMcode curl_multi_cleanup(CURLM *multi_handle)
#define multi_timeout(A, B)
Definition: test.h:353


rc_tagdetect_client
Author(s): Monika Florek-Jasinska , Raphael Schaller
autogenerated on Sat Feb 13 2021 03:42:15