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