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 "testtrace.h"
00025 #include "memdebug.h"
00026
00027 #ifdef LIB585
00028
00029 static int counter;
00030
00031 static curl_socket_t tst_opensocket(void *clientp,
00032 curlsocktype purpose,
00033 struct curl_sockaddr *addr)
00034 {
00035 (void)clientp;
00036 (void)purpose;
00037 printf("[OPEN] counter: %d\n", ++counter);
00038 return socket(addr->family, addr->socktype, addr->protocol);
00039 }
00040
00041 static int tst_closesocket(void *clientp, curl_socket_t sock)
00042 {
00043 (void)clientp;
00044 printf("[CLOSE] counter: %d\n", counter--);
00045 return sclose(sock);
00046 }
00047
00048 static void setupcallbacks(CURL *curl)
00049 {
00050 curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, tst_opensocket);
00051 curl_easy_setopt(curl, CURLOPT_CLOSESOCKETFUNCTION, tst_closesocket);
00052 counter = 0;
00053 }
00054
00055 #else
00056 #define setupcallbacks(x) Curl_nop_stmt
00057 #endif
00058
00059
00060 int test(char *URL)
00061 {
00062 CURLcode res;
00063 CURL *curl;
00064 char *ipstr=NULL;
00065
00066 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
00067 fprintf(stderr, "curl_global_init() failed\n");
00068 return TEST_ERR_MAJOR_BAD;
00069 }
00070
00071 curl = curl_easy_init();
00072 if(!curl) {
00073 fprintf(stderr, "curl_easy_init() failed\n");
00074 curl_global_cleanup();
00075 return TEST_ERR_MAJOR_BAD;
00076 }
00077
00078 test_setopt(curl, CURLOPT_URL, URL);
00079 test_setopt(curl, CURLOPT_HEADER, 1L);
00080
00081 libtest_debug_config.nohex = 1;
00082 libtest_debug_config.tracetime = 1;
00083 test_setopt(curl, CURLOPT_DEBUGDATA, &libtest_debug_config);
00084 test_setopt(curl, CURLOPT_DEBUGFUNCTION, libtest_debug_cb);
00085 test_setopt(curl, CURLOPT_VERBOSE, 1L);
00086
00087 if(libtest_arg3 && !strcmp(libtest_arg3, "activeftp"))
00088 test_setopt(curl, CURLOPT_FTPPORT, "-");
00089
00090 setupcallbacks(curl);
00091
00092 res = curl_easy_perform(curl);
00093
00094 if(!res) {
00095 res = curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ipstr);
00096 if(libtest_arg2) {
00097 FILE *moo = fopen(libtest_arg2, "wb");
00098 if(moo) {
00099 double time_namelookup;
00100 double time_connect;
00101 double time_pretransfer;
00102 double time_starttransfer;
00103 double time_total;
00104 fprintf(moo, "IP: %s\n", ipstr);
00105 curl_easy_getinfo(curl, CURLINFO_NAMELOOKUP_TIME, &time_namelookup);
00106 curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME, &time_connect);
00107 curl_easy_getinfo(curl, CURLINFO_PRETRANSFER_TIME, &time_pretransfer);
00108 curl_easy_getinfo(curl, CURLINFO_STARTTRANSFER_TIME,
00109 &time_starttransfer);
00110 curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &time_total);
00111
00112
00113
00114 if(time_namelookup > time_connect) {
00115 fprintf(moo, "namelookup vs connect: %f %f\n",
00116 time_namelookup, time_connect);
00117 }
00118 if(time_connect > time_pretransfer) {
00119 fprintf(moo, "connect vs pretransfer: %f %f\n",
00120 time_connect, time_pretransfer);
00121 }
00122 if(time_pretransfer > time_starttransfer) {
00123 fprintf(moo, "pretransfer vs starttransfer: %f %f\n",
00124 time_pretransfer, time_starttransfer);
00125 }
00126 if(time_starttransfer > time_total) {
00127 fprintf(moo, "starttransfer vs total: %f %f\n",
00128 time_starttransfer, time_total);
00129 }
00130
00131 fclose(moo);
00132 }
00133 }
00134 }
00135
00136 test_cleanup:
00137
00138 curl_easy_cleanup(curl);
00139 curl_global_cleanup();
00140
00141 return (int)res;
00142 }
00143