1/*************************************************************************** 2 * _ _ ____ _ 3 * Project ___| | | | _ \| | 4 * / __| | | | |_) | | 5 * | (__| |_| | _ <| |___ 6 * \___|\___/|_| \_\_____| 7 * 8 * Copyright (C) 1998 - 2011, 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 http://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#include <fcntl.h> 27 28#include "testutil.h" 29#include "warnless.h" 30#include "memdebug.h" 31 32#define TEST_HANG_TIMEOUT 60 * 1000 33 34int test(char *URL) 35{ 36 CURL *easy = NULL; 37 CURLM *multi = NULL; 38 int res = 0; 39 int running; 40 int msgs_left; 41 CURLMsg *msg; 42 FILE *upload = NULL; 43 int error; 44 45 start_test_timing(); 46 47 upload = fopen(libtest_arg3, "rb"); 48 if(!upload) { 49 error = ERRNO; 50 fprintf(stderr, "fopen() failed with error: %d (%s)\n", 51 error, strerror(error)); 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_CONNECTTIMEOUT, strtol(libtest_arg2, NULL, 10)); 81 82 multi_init(multi); 83 84 multi_add_handle(multi, easy); 85 86 for(;;) { 87 struct timeval interval; 88 fd_set fdread; 89 fd_set fdwrite; 90 fd_set fdexcep; 91 long timeout = -99; 92 int maxfd = -99; 93 94 multi_perform(multi, &running); 95 96 abort_on_test_timeout(); 97 98 if(!running) 99 break; /* done */ 100 101 FD_ZERO(&fdread); 102 FD_ZERO(&fdwrite); 103 FD_ZERO(&fdexcep); 104 105 multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd); 106 107 /* At this point, maxfd is guaranteed to be greater or equal than -1. */ 108 109 multi_timeout(multi, &timeout); 110 111 /* At this point, timeout is guaranteed to be greater or equal than -1. */ 112 113 if(timeout != -1L) { 114 interval.tv_sec = timeout/1000; 115 interval.tv_usec = (timeout%1000)*1000; 116 } 117 else { 118 interval.tv_sec = 0; 119 interval.tv_usec = 100000L; /* 100 ms */ 120 } 121 122 select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &interval); 123 124 abort_on_test_timeout(); 125 } 126 127 msg = curl_multi_info_read(multi, &msgs_left); 128 if(msg) 129 res = msg->data.result; 130 131test_cleanup: 132 133 /* undocumented cleanup sequence - type UA */ 134 135 curl_multi_cleanup(multi); 136 curl_easy_cleanup(easy); 137 curl_global_cleanup(); 138 139 /* close the local file */ 140 fclose(upload); 141 142 return res; 143} 144