00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "test.h"
00030 #include "testutil.h"
00031 #include "warnless.h"
00032 #include "memdebug.h"
00033
00034 #define TEST_HANG_TIMEOUT 60 * 1000
00035
00036 #define DNS_TIMEOUT 1
00037
00038 #if defined(WIN32) || defined(_WIN32)
00039 #define sleep(s) Sleep(s * 1000)
00040 #endif
00041
00042 static int debug_callback(CURL *curl, curl_infotype info, char *msg,
00043 size_t len, void *ptr)
00044 {
00045 (void)curl;
00046 (void)ptr;
00047
00048 if(info == CURLINFO_TEXT)
00049 fprintf(stderr, "debug: %.*s", (int) len, msg);
00050
00051 return 0;
00052 }
00053
00054 static int do_one_request(CURLM *m, char *URL, char *resolve)
00055 {
00056 CURL *curls;
00057 struct curl_slist *resolve_list = NULL;
00058 int still_running;
00059 int res = 0;
00060 CURLMsg *msg;
00061 int msgs_left;
00062
00063 resolve_list = curl_slist_append(resolve_list, resolve);
00064
00065 easy_init(curls);
00066
00067 easy_setopt(curls, CURLOPT_URL, URL);
00068 easy_setopt(curls, CURLOPT_RESOLVE, resolve_list);
00069 easy_setopt(curls, CURLOPT_DEBUGFUNCTION, debug_callback);
00070 easy_setopt(curls, CURLOPT_VERBOSE, 1);
00071 easy_setopt(curls, CURLOPT_DNS_CACHE_TIMEOUT, DNS_TIMEOUT);
00072
00073 multi_add_handle(m, curls);
00074 multi_perform(m, &still_running);
00075
00076 abort_on_test_timeout();
00077
00078 while(still_running) {
00079 struct timeval timeout;
00080 fd_set fdread, fdwrite, fdexcep;
00081 int maxfd = -99;
00082
00083 FD_ZERO(&fdread);
00084 FD_ZERO(&fdwrite);
00085 FD_ZERO(&fdexcep);
00086 timeout.tv_sec = 1;
00087 timeout.tv_usec = 0;
00088
00089 multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
00090 select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
00091
00092 abort_on_test_timeout();
00093 multi_perform(m, &still_running);
00094
00095 abort_on_test_timeout();
00096 }
00097
00098 while((msg = curl_multi_info_read(m, &msgs_left))) {
00099 if(msg->msg == CURLMSG_DONE && msg->easy_handle == curls) {
00100 res = msg->data.result;
00101 break;
00102 }
00103 }
00104
00105 test_cleanup:
00106
00107 curl_multi_remove_handle(m, curls);
00108 curl_easy_cleanup(curls);
00109 curl_slist_free_all(resolve_list);
00110
00111 return res;
00112 }
00113
00114 int test(char *URL)
00115 {
00116 CURLM *multi = NULL;
00117 int res = 0;
00118 char *address = libtest_arg2;
00119 char *port = libtest_arg3;
00120 char *path = URL;
00121 char dns_entry[256];
00122 int i;
00123 int count = 2;
00124
00125 snprintf(dns_entry, sizeof(dns_entry), "testserver.example.com:%s:%s",
00126 port, address);
00127
00128 start_test_timing();
00129
00130 global_init(CURL_GLOBAL_ALL);
00131 multi_init(multi);
00132
00133 for(i = 1; i <= count; i++) {
00134 char target_url[256];
00135 snprintf(target_url, sizeof(target_url),
00136 "http://testserver.example.com:%s/%s%04d", port, path, i);
00137
00138
00139 res = do_one_request(multi, target_url, dns_entry);
00140 if(res)
00141 goto test_cleanup;
00142
00143 if(i < count)
00144 sleep(DNS_TIMEOUT + 1);
00145 }
00146
00147 test_cleanup:
00148
00149 curl_multi_cleanup(multi);
00150
00151 return (int) res;
00152 }