lib500.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
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         /* since the timing will always vary we only compare relative
00113            differences between these 5 times */
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 


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:05