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
00025
00026 #ifdef HAVE_LIMITS_H
00027 #include <limits.h>
00028 #endif
00029
00030 #include <fcntl.h>
00031
00032 #include "testutil.h"
00033 #include "warnless.h"
00034 #include "memdebug.h"
00035
00036 #define TEST_HANG_TIMEOUT 60 * 1000
00037
00038 int test(char *URL)
00039 {
00040 CURL *easy = NULL;
00041 CURLM *multi = NULL;
00042 int res = 0;
00043 int running;
00044 int msgs_left;
00045 CURLMsg *msg;
00046 FILE *upload = NULL;
00047 int error;
00048
00049 start_test_timing();
00050
00051 upload = fopen(libtest_arg3, "rb");
00052 if(!upload) {
00053 error = ERRNO;
00054 fprintf(stderr, "fopen() failed with error: %d (%s)\n",
00055 error, strerror(error));
00056 fprintf(stderr, "Error opening file: (%s)\n", libtest_arg3);
00057 return TEST_ERR_FOPEN;
00058 }
00059
00060 res_global_init(CURL_GLOBAL_ALL);
00061 if(res) {
00062 fclose(upload);
00063 return res;
00064 }
00065
00066 easy_init(easy);
00067
00068
00069 easy_setopt(easy, CURLOPT_VERBOSE, 1L);
00070
00071
00072 easy_setopt(easy, CURLOPT_URL, URL);
00073
00074
00075 easy_setopt(easy, CURLOPT_UPLOAD, 1L);
00076
00077
00078 easy_setopt(easy, CURLOPT_READDATA, upload);
00079
00080
00081 easy_setopt(easy, CURLOPT_FTPPORT, "-");
00082
00083
00084 easy_setopt(easy, CURLOPT_ACCEPTTIMEOUT_MS,
00085 strtol(libtest_arg2, NULL, 10)*1000);
00086
00087 multi_init(multi);
00088
00089 multi_add_handle(multi, easy);
00090
00091 for(;;) {
00092 struct timeval interval;
00093 fd_set fdread;
00094 fd_set fdwrite;
00095 fd_set fdexcep;
00096 long timeout = -99;
00097 int maxfd = -99;
00098
00099 multi_perform(multi, &running);
00100
00101 abort_on_test_timeout();
00102
00103 if(!running)
00104 break;
00105
00106 FD_ZERO(&fdread);
00107 FD_ZERO(&fdwrite);
00108 FD_ZERO(&fdexcep);
00109
00110 multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
00111
00112
00113
00114 multi_timeout(multi, &timeout);
00115
00116
00117
00118 if(timeout != -1L) {
00119 int itimeout = (timeout > (long)INT_MAX) ? INT_MAX : (int)timeout;
00120 interval.tv_sec = itimeout/1000;
00121 interval.tv_usec = (itimeout%1000)*1000;
00122 }
00123 else {
00124 interval.tv_sec = 0;
00125 interval.tv_usec = 100000L;
00126 }
00127
00128 select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &interval);
00129
00130 abort_on_test_timeout();
00131 }
00132
00133 msg = curl_multi_info_read(multi, &msgs_left);
00134 if(msg)
00135 res = msg->data.result;
00136
00137 test_cleanup:
00138
00139
00140
00141 curl_multi_cleanup(multi);
00142 curl_easy_cleanup(easy);
00143 curl_global_cleanup();
00144
00145
00146 fclose(upload);
00147
00148 return res;
00149 }