2011-10-27 00:55:35 +08:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2023-01-02 20:51:48 +08:00
|
|
|
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
2011-10-27 00:55:35 +08:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2020-11-04 21:02:01 +08:00
|
|
|
* are also available at https://curl.se/docs/copyright.html.
|
2011-10-27 00:55:35 +08:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: curl
|
2022-05-17 17:16:50 +08:00
|
|
|
*
|
2011-10-27 00:55:35 +08:00
|
|
|
***************************************************************************/
|
|
|
|
#include "test.h"
|
|
|
|
|
2011-11-12 02:46:44 +08:00
|
|
|
/* lib591 is used for test cases 591, 592, 593 and 594 */
|
|
|
|
|
2012-12-06 00:28:32 +08:00
|
|
|
#include <limits.h>
|
|
|
|
|
2011-10-27 00:55:35 +08:00
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include "testutil.h"
|
2013-01-04 09:50:28 +08:00
|
|
|
#include "warnless.h"
|
|
|
|
#include "memdebug.h"
|
2011-10-27 00:55:35 +08:00
|
|
|
|
|
|
|
#define TEST_HANG_TIMEOUT 60 * 1000
|
|
|
|
|
2024-05-12 03:36:05 +08:00
|
|
|
CURLcode test(char *URL)
|
2011-10-27 00:55:35 +08:00
|
|
|
{
|
|
|
|
CURL *easy = NULL;
|
|
|
|
CURLM *multi = NULL;
|
2024-05-12 03:36:05 +08:00
|
|
|
CURLcode res = CURLE_OK;
|
2011-10-27 00:55:35 +08:00
|
|
|
int running;
|
|
|
|
int msgs_left;
|
|
|
|
CURLMsg *msg;
|
2011-10-28 04:00:23 +08:00
|
|
|
FILE *upload = NULL;
|
2011-10-27 00:55:35 +08:00
|
|
|
|
|
|
|
start_test_timing();
|
|
|
|
|
2011-11-12 02:46:44 +08:00
|
|
|
upload = fopen(libtest_arg3, "rb");
|
2011-10-28 04:00:23 +08:00
|
|
|
if(!upload) {
|
|
|
|
fprintf(stderr, "fopen() failed with error: %d (%s)\n",
|
2017-07-11 13:53:23 +08:00
|
|
|
errno, strerror(errno));
|
2011-11-12 02:46:44 +08:00
|
|
|
fprintf(stderr, "Error opening file: (%s)\n", libtest_arg3);
|
2011-10-28 04:00:23 +08:00
|
|
|
return TEST_ERR_FOPEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
res_global_init(CURL_GLOBAL_ALL);
|
|
|
|
if(res) {
|
|
|
|
fclose(upload);
|
|
|
|
return res;
|
|
|
|
}
|
2011-10-27 00:55:35 +08:00
|
|
|
|
|
|
|
easy_init(easy);
|
|
|
|
|
2011-10-28 04:00:23 +08:00
|
|
|
/* go verbose */
|
2011-10-27 00:55:35 +08:00
|
|
|
easy_setopt(easy, CURLOPT_VERBOSE, 1L);
|
2011-10-28 04:00:23 +08:00
|
|
|
|
|
|
|
/* specify target */
|
|
|
|
easy_setopt(easy, CURLOPT_URL, URL);
|
|
|
|
|
|
|
|
/* enable uploading */
|
2011-10-27 00:55:35 +08:00
|
|
|
easy_setopt(easy, CURLOPT_UPLOAD, 1L);
|
2011-10-28 04:00:23 +08:00
|
|
|
|
|
|
|
/* data pointer for the file read function */
|
|
|
|
easy_setopt(easy, CURLOPT_READDATA, upload);
|
|
|
|
|
|
|
|
/* use active mode FTP */
|
2011-10-27 00:55:35 +08:00
|
|
|
easy_setopt(easy, CURLOPT_FTPPORT, "-");
|
|
|
|
|
2011-11-12 02:46:44 +08:00
|
|
|
/* server connection timeout */
|
2011-12-19 21:35:20 +08:00
|
|
|
easy_setopt(easy, CURLOPT_ACCEPTTIMEOUT_MS,
|
|
|
|
strtol(libtest_arg2, NULL, 10)*1000);
|
2011-11-12 02:46:44 +08:00
|
|
|
|
2011-10-27 00:55:35 +08:00
|
|
|
multi_init(multi);
|
|
|
|
|
|
|
|
multi_add_handle(multi, easy);
|
|
|
|
|
|
|
|
for(;;) {
|
|
|
|
struct timeval interval;
|
|
|
|
fd_set fdread;
|
|
|
|
fd_set fdwrite;
|
|
|
|
fd_set fdexcep;
|
|
|
|
long timeout = -99;
|
|
|
|
int maxfd = -99;
|
|
|
|
|
|
|
|
multi_perform(multi, &running);
|
|
|
|
|
|
|
|
abort_on_test_timeout();
|
|
|
|
|
|
|
|
if(!running)
|
|
|
|
break; /* done */
|
|
|
|
|
|
|
|
FD_ZERO(&fdread);
|
|
|
|
FD_ZERO(&fdwrite);
|
|
|
|
FD_ZERO(&fdexcep);
|
|
|
|
|
|
|
|
multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
|
|
|
|
|
|
|
|
/* At this point, maxfd is guaranteed to be greater or equal than -1. */
|
|
|
|
|
|
|
|
multi_timeout(multi, &timeout);
|
|
|
|
|
|
|
|
/* At this point, timeout is guaranteed to be greater or equal than -1. */
|
|
|
|
|
|
|
|
if(timeout != -1L) {
|
2023-09-24 17:50:39 +08:00
|
|
|
int itimeout;
|
|
|
|
#if LONG_MAX > INT_MAX
|
|
|
|
itimeout = (timeout > (long)INT_MAX) ? INT_MAX : (int)timeout;
|
|
|
|
#else
|
|
|
|
itimeout = (int)timeout;
|
|
|
|
#endif
|
2012-12-06 00:28:32 +08:00
|
|
|
interval.tv_sec = itimeout/1000;
|
|
|
|
interval.tv_usec = (itimeout%1000)*1000;
|
2011-10-27 00:55:35 +08:00
|
|
|
}
|
|
|
|
else {
|
2011-10-28 04:00:23 +08:00
|
|
|
interval.tv_sec = 0;
|
|
|
|
interval.tv_usec = 100000L; /* 100 ms */
|
2011-10-27 00:55:35 +08:00
|
|
|
}
|
|
|
|
|
2017-09-10 05:55:08 +08:00
|
|
|
select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &interval);
|
2011-10-27 00:55:35 +08:00
|
|
|
|
|
|
|
abort_on_test_timeout();
|
|
|
|
}
|
|
|
|
|
|
|
|
msg = curl_multi_info_read(multi, &msgs_left);
|
|
|
|
if(msg)
|
|
|
|
res = msg->data.result;
|
|
|
|
|
|
|
|
test_cleanup:
|
|
|
|
|
|
|
|
/* undocumented cleanup sequence - type UA */
|
|
|
|
|
|
|
|
curl_multi_cleanup(multi);
|
|
|
|
curl_easy_cleanup(easy);
|
|
|
|
curl_global_cleanup();
|
|
|
|
|
2011-10-28 04:00:23 +08:00
|
|
|
/* close the local file */
|
|
|
|
fclose(upload);
|
|
|
|
|
2011-10-27 00:55:35 +08:00
|
|
|
return res;
|
|
|
|
}
|