1 | /*************************************************************************** |
2 | * _ _ ____ _ |
3 | * Project ___| | | | _ \| | |
4 | * / __| | | | |_) | | |
5 | * | (__| |_| | _ <| |___ |
6 | * \___|\___/|_| \_\_____| |
7 | * |
8 | * Copyright (C) 1998 - 2020, 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 | ***************************************************************************/ |
22 | #include "test.h" |
23 | |
24 | /* lib591 is used for test cases 591, 592, 593 and 594 */ |
25 | |
26 | #include <limits.h> |
27 | |
28 | #include <fcntl.h> |
29 | |
30 | #include "testutil.h" |
31 | #include "warnless.h" |
32 | #include "memdebug.h" |
33 | |
34 | #define TEST_HANG_TIMEOUT 60 * 1000 |
35 | |
36 | int test(char *URL) |
37 | { |
38 | CURL *easy = NULL; |
39 | CURLM *multi = NULL; |
40 | int res = 0; |
41 | int running; |
42 | int msgs_left; |
43 | CURLMsg *msg; |
44 | FILE *upload = NULL; |
45 | |
46 | start_test_timing(); |
47 | |
48 | upload = fopen(libtest_arg3, "rb" ); |
49 | if(!upload) { |
50 | fprintf(stderr, "fopen() failed with error: %d (%s)\n" , |
51 | errno, strerror(errno)); |
52 | fprintf(stderr, "Error opening file: (%s)\n" , libtest_arg3); |
53 | return TEST_ERR_FOPEN; |
54 | } |
55 | |
56 | res_global_init(CURL_GLOBAL_ALL); |
57 | if(res) { |
58 | fclose(upload); |
59 | return res; |
60 | } |
61 | |
62 | easy_init(easy); |
63 | |
64 | /* go verbose */ |
65 | easy_setopt(easy, CURLOPT_VERBOSE, 1L); |
66 | |
67 | /* specify target */ |
68 | easy_setopt(easy, CURLOPT_URL, URL); |
69 | |
70 | /* enable uploading */ |
71 | easy_setopt(easy, CURLOPT_UPLOAD, 1L); |
72 | |
73 | /* data pointer for the file read function */ |
74 | easy_setopt(easy, CURLOPT_READDATA, upload); |
75 | |
76 | /* use active mode FTP */ |
77 | easy_setopt(easy, CURLOPT_FTPPORT, "-" ); |
78 | |
79 | /* server connection timeout */ |
80 | easy_setopt(easy, CURLOPT_ACCEPTTIMEOUT_MS, |
81 | strtol(libtest_arg2, NULL, 10)*1000); |
82 | |
83 | multi_init(multi); |
84 | |
85 | multi_add_handle(multi, easy); |
86 | |
87 | for(;;) { |
88 | struct timeval interval; |
89 | fd_set fdread; |
90 | fd_set fdwrite; |
91 | fd_set fdexcep; |
92 | long timeout = -99; |
93 | int maxfd = -99; |
94 | |
95 | multi_perform(multi, &running); |
96 | |
97 | abort_on_test_timeout(); |
98 | |
99 | if(!running) |
100 | break; /* done */ |
101 | |
102 | FD_ZERO(&fdread); |
103 | FD_ZERO(&fdwrite); |
104 | FD_ZERO(&fdexcep); |
105 | |
106 | multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd); |
107 | |
108 | /* At this point, maxfd is guaranteed to be greater or equal than -1. */ |
109 | |
110 | multi_timeout(multi, &timeout); |
111 | |
112 | /* At this point, timeout is guaranteed to be greater or equal than -1. */ |
113 | |
114 | if(timeout != -1L) { |
115 | int itimeout = (timeout > (long)INT_MAX) ? INT_MAX : (int)timeout; |
116 | interval.tv_sec = itimeout/1000; |
117 | interval.tv_usec = (itimeout%1000)*1000; |
118 | } |
119 | else { |
120 | interval.tv_sec = 0; |
121 | interval.tv_usec = 100000L; /* 100 ms */ |
122 | } |
123 | |
124 | select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &interval); |
125 | |
126 | abort_on_test_timeout(); |
127 | } |
128 | |
129 | msg = curl_multi_info_read(multi, &msgs_left); |
130 | if(msg) |
131 | res = msg->data.result; |
132 | |
133 | test_cleanup: |
134 | |
135 | /* undocumented cleanup sequence - type UA */ |
136 | |
137 | curl_multi_cleanup(multi); |
138 | curl_easy_cleanup(easy); |
139 | curl_global_cleanup(); |
140 | |
141 | /* close the local file */ |
142 | fclose(upload); |
143 | |
144 | return res; |
145 | } |
146 | |