Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "test.h"
00023
00024 #include <fcntl.h>
00025
00026 #include "testutil.h"
00027 #include "warnless.h"
00028 #include "memdebug.h"
00029
00030 #define TEST_HANG_TIMEOUT 60 * 1000
00031
00032 int test(char *URL)
00033 {
00034 int res = 0;
00035 CURL *curl = NULL;
00036 FILE *hd_src = NULL;
00037 int hd;
00038 int error;
00039 struct_stat file_info;
00040 CURLM *m = NULL;
00041 int running;
00042
00043 start_test_timing();
00044
00045 if(!libtest_arg2) {
00046 #ifdef LIB529
00047
00048 fprintf(stderr, "Usage: lib529 [url] [uploadfile]\n");
00049 #else
00050
00051 fprintf(stderr, "Usage: lib525 [url] [uploadfile]\n");
00052 #endif
00053 return TEST_ERR_USAGE;
00054 }
00055
00056 hd_src = fopen(libtest_arg2, "rb");
00057 if(NULL == hd_src) {
00058 error = ERRNO;
00059 fprintf(stderr, "fopen failed with error: %d (%s)\n",
00060 error, strerror(error));
00061 fprintf(stderr, "Error opening file: (%s)\n", libtest_arg2);
00062 return TEST_ERR_FOPEN;
00063 }
00064
00065
00066 hd = fstat(fileno(hd_src), &file_info);
00067 if(hd == -1) {
00068
00069 error = ERRNO;
00070 fprintf(stderr, "fstat() failed with error: %d (%s)\n",
00071 error, strerror(error));
00072 fprintf(stderr, "ERROR: cannot open file (%s)\n", libtest_arg2);
00073 fclose(hd_src);
00074 return TEST_ERR_FSTAT;
00075 }
00076
00077 res_global_init(CURL_GLOBAL_ALL);
00078 if(res) {
00079 fclose(hd_src);
00080 return res;
00081 }
00082
00083 easy_init(curl);
00084
00085
00086 easy_setopt(curl, CURLOPT_UPLOAD, 1L);
00087
00088
00089 easy_setopt(curl, CURLOPT_URL, URL);
00090
00091
00092 easy_setopt(curl, CURLOPT_VERBOSE, 1L);
00093
00094
00095 easy_setopt(curl, CURLOPT_FTPPORT, "-");
00096
00097
00098 easy_setopt(curl, CURLOPT_READDATA, hd_src);
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_info.st_size);
00110
00111 multi_init(m);
00112
00113 multi_add_handle(m, curl);
00114
00115 for(;;) {
00116 struct timeval interval;
00117 fd_set rd, wr, exc;
00118 int maxfd = -99;
00119
00120 interval.tv_sec = 1;
00121 interval.tv_usec = 0;
00122
00123 multi_perform(m, &running);
00124
00125 abort_on_test_timeout();
00126
00127 if(!running)
00128 break;
00129
00130 FD_ZERO(&rd);
00131 FD_ZERO(&wr);
00132 FD_ZERO(&exc);
00133
00134 multi_fdset(m, &rd, &wr, &exc, &maxfd);
00135
00136
00137
00138 select_test(maxfd+1, &rd, &wr, &exc, &interval);
00139
00140 abort_on_test_timeout();
00141 }
00142
00143 test_cleanup:
00144
00145 #ifdef LIB529
00146
00147
00148 curl_multi_remove_handle(m, curl);
00149 curl_multi_cleanup(m);
00150 curl_easy_cleanup(curl);
00151 curl_global_cleanup();
00152 #else
00153
00154
00155 curl_multi_remove_handle(m, curl);
00156 curl_easy_cleanup(curl);
00157 curl_multi_cleanup(m);
00158 curl_global_cleanup();
00159 #endif
00160
00161
00162 fclose(hd_src);
00163
00164 return res;
00165 }