1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
24 #include "testtrace.h"
31 static curl_socket_t tst_opensocket(void *clientp,
33 struct curl_sockaddr *addr)
37 printf("[OPEN] counter: %d\n", ++counter);
38 return socket(addr->family, addr->socktype, addr->protocol);
41 static int tst_closesocket(void *clientp, curl_socket_t sock)
44 printf("[CLOSE] counter: %d\n", counter--);
48 static void setupcallbacks(CURL *curl)
50 curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, tst_opensocket);
51 curl_easy_setopt(curl, CURLOPT_CLOSESOCKETFUNCTION, tst_closesocket);
56 #define setupcallbacks(x) Curl_nop_stmt
66 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
67 fprintf(stderr, "curl_global_init() failed\n");
68 return TEST_ERR_MAJOR_BAD;
71 curl = curl_easy_init();
73 fprintf(stderr, "curl_easy_init() failed\n");
74 curl_global_cleanup();
75 return TEST_ERR_MAJOR_BAD;
78 test_setopt(curl, CURLOPT_URL, URL);
79 test_setopt(curl, CURLOPT_HEADER, 1L);
81 libtest_debug_config.nohex = 1;
82 libtest_debug_config.tracetime = 1;
83 test_setopt(curl, CURLOPT_DEBUGDATA, &libtest_debug_config);
84 test_setopt(curl, CURLOPT_DEBUGFUNCTION, libtest_debug_cb);
85 test_setopt(curl, CURLOPT_VERBOSE, 1L);
87 if(libtest_arg3 && !strcmp(libtest_arg3, "activeftp"))
88 test_setopt(curl, CURLOPT_FTPPORT, "-");
92 res = curl_easy_perform(curl);
95 res = curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ipstr);
97 FILE *moo = fopen(libtest_arg2, "wb");
99 double time_namelookup;
101 double time_pretransfer;
102 double time_starttransfer;
104 fprintf(moo, "IP: %s\n", ipstr);
105 curl_easy_getinfo(curl, CURLINFO_NAMELOOKUP_TIME, &time_namelookup);
106 curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME, &time_connect);
107 curl_easy_getinfo(curl, CURLINFO_PRETRANSFER_TIME, &time_pretransfer);
108 curl_easy_getinfo(curl, CURLINFO_STARTTRANSFER_TIME,
109 &time_starttransfer);
110 curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &time_total);
112 /* since the timing will always vary we only compare relative
113 differences between these 5 times */
114 if(time_namelookup > time_connect) {
115 fprintf(moo, "namelookup vs connect: %f %f\n",
116 time_namelookup, time_connect);
118 if(time_connect > time_pretransfer) {
119 fprintf(moo, "connect vs pretransfer: %f %f\n",
120 time_connect, time_pretransfer);
122 if(time_pretransfer > time_starttransfer) {
123 fprintf(moo, "pretransfer vs starttransfer: %f %f\n",
124 time_pretransfer, time_starttransfer);
126 if(time_starttransfer > time_total) {
127 fprintf(moo, "starttransfer vs total: %f %f\n",
128 time_starttransfer, time_total);
138 curl_easy_cleanup(curl);
139 curl_global_cleanup();