lib591.c
Go to the documentation of this file.
1 /***************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2012, 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 /* lib591 is used for test cases 591, 592, 593 and 594 */
25 
26 #ifdef HAVE_LIMITS_H
27 #include <limits.h>
28 #endif
29 
30 #include <fcntl.h>
31 
32 #include "testutil.h"
33 #include "warnless.h"
34 #include "memdebug.h"
35 
36 #define TEST_HANG_TIMEOUT 60 * 1000
37 
38 int test(char *URL)
39 {
40  CURL *easy = NULL;
41  CURLM *multi = NULL;
42  int res = 0;
43  int running;
44  int msgs_left;
45  CURLMsg *msg;
46  FILE *upload = NULL;
47 
49 
50  upload = fopen(libtest_arg3, "rb");
51  if(!upload) {
52  fprintf(stderr, "fopen() failed with error: %d (%s)\n",
53  errno, strerror(errno));
54  fprintf(stderr, "Error opening file: (%s)\n", libtest_arg3);
55  return TEST_ERR_FOPEN;
56  }
57 
59  if(res) {
60  fclose(upload);
61  return res;
62  }
63 
64  easy_init(easy);
65 
66  /* go verbose */
67  easy_setopt(easy, CURLOPT_VERBOSE, 1L);
68 
69  /* specify target */
70  easy_setopt(easy, CURLOPT_URL, URL);
71 
72  /* enable uploading */
73  easy_setopt(easy, CURLOPT_UPLOAD, 1L);
74 
75  /* data pointer for the file read function */
76  easy_setopt(easy, CURLOPT_READDATA, upload);
77 
78  /* use active mode FTP */
79  easy_setopt(easy, CURLOPT_FTPPORT, "-");
80 
81  /* server connection timeout */
82  easy_setopt(easy, CURLOPT_ACCEPTTIMEOUT_MS,
83  strtol(libtest_arg2, NULL, 10)*1000);
84 
85  multi_init(multi);
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 -1. */
115 
116  if(timeout != -1L) {
117  int itimeout = (timeout > (long)INT_MAX) ? INT_MAX : (int)timeout;
118  interval.tv_sec = itimeout/1000;
119  interval.tv_usec = (itimeout%1000)*1000;
120  }
121  else {
122  interval.tv_sec = 0;
123  interval.tv_usec = 100000L; /* 100 ms */
124  }
125 
126  select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &interval);
127 
129  }
130 
131  msg = curl_multi_info_read(multi, &msgs_left);
132  if(msg)
133  res = msg->data.result;
134 
135 test_cleanup:
136 
137  /* undocumented cleanup sequence - type UA */
138 
139  curl_multi_cleanup(multi);
140  curl_easy_cleanup(easy);
142 
143  /* close the local file */
144  fclose(upload);
145 
146  return res;
147 }
#define select_test(A, B, C, D, E)
Definition: test.h:378
#define res_global_init(A)
Definition: test.h:419
int test(char *URL)
Definition: lib591.c:38
#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
char * libtest_arg2
Definition: first.c:75
static int upload(CURL *curlhandle, const char *remotepath, const char *localpath, long timeout, long tries)
#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_perform(A, B)
Definition: test.h:293
#define multi_init(A)
Definition: test.h:166
#define TEST_ERR_FOPEN
Definition: test.h:94
char * libtest_arg3
Definition: first.c:76
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
#define fprintf
Definition: curl_printf.h:41
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