lib500.c
Go to the documentation of this file.
1 /***************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
9  *
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.
13  *
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.
17  *
18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19  * KIND, either express or implied.
20  *
21  ***************************************************************************/
22 #include "test.h"
23 
24 #include "testtrace.h"
25 #include "memdebug.h"
26 
27 #ifdef LIB585
28 
29 static int counter;
30 
31 static curl_socket_t tst_opensocket(void *clientp,
32  curlsocktype purpose,
33  struct curl_sockaddr *addr)
34 {
35  (void)clientp;
36  (void)purpose;
37  printf("[OPEN] counter: %d\n", ++counter);
38  return socket(addr->family, addr->socktype, addr->protocol);
39 }
40 
41 static int tst_closesocket(void *clientp, curl_socket_t sock)
42 {
43  (void)clientp;
44  printf("[CLOSE] counter: %d\n", counter--);
45  return sclose(sock);
46 }
47 
48 static void setupcallbacks(CURL *curl)
49 {
50  curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, tst_opensocket);
51  curl_easy_setopt(curl, CURLOPT_CLOSESOCKETFUNCTION, tst_closesocket);
52  counter = 0;
53 }
54 
55 #else
56 #define setupcallbacks(x) Curl_nop_stmt
57 #endif
58 
59 
60 int test(char *URL)
61 {
62  CURLcode res;
63  CURL *curl;
64  char *ipstr = NULL;
65 
67  fprintf(stderr, "curl_global_init() failed\n");
68  return TEST_ERR_MAJOR_BAD;
69  }
70 
71  curl = curl_easy_init();
72  if(!curl) {
73  fprintf(stderr, "curl_easy_init() failed\n");
75  return TEST_ERR_MAJOR_BAD;
76  }
77 
78  test_setopt(curl, CURLOPT_URL, URL);
79  test_setopt(curl, CURLOPT_HEADER, 1L);
80 
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);
86 
87  if(libtest_arg3 && !strcmp(libtest_arg3, "activeftp"))
88  test_setopt(curl, CURLOPT_FTPPORT, "-");
89 
90  setupcallbacks(curl);
91 
92  res = curl_easy_perform(curl);
93 
94  if(!res) {
95  res = curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ipstr);
96  if(libtest_arg2) {
97  FILE *moo = fopen(libtest_arg2, "wb");
98  if(moo) {
99  double time_namelookup;
100  double time_connect;
101  double time_pretransfer;
102  double time_starttransfer;
103  double time_total;
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);
109  &time_starttransfer);
110  curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &time_total);
111 
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);
117  }
118  if(time_connect > time_pretransfer) {
119  fprintf(moo, "connect vs pretransfer: %f %f\n",
120  time_connect, time_pretransfer);
121  }
122  if(time_pretransfer > time_starttransfer) {
123  fprintf(moo, "pretransfer vs starttransfer: %f %f\n",
124  time_pretransfer, time_starttransfer);
125  }
126  if(time_starttransfer > time_total) {
127  fprintf(moo, "starttransfer vs total: %f %f\n",
128  time_starttransfer, time_total);
129  }
130 
131  fclose(moo);
132  }
133  }
134  }
135 
136 test_cleanup:
137 
138  curl_easy_cleanup(curl);
140 
141  return (int)res;
142 }
143 
#define setupcallbacks(x)
Definition: lib500.c:56
#define test_setopt(A, B, C)
Definition: test.h:47
#define sclose(x)
int family
Definition: curl.h:378
int libtest_debug_cb(CURL *handle, curl_infotype type, unsigned char *data, size_t size, void *userp)
Definition: testtrace.c:85
CURLcode
Definition: curl.h:454
int protocol
Definition: curl.h:380
static int res
#define curl_easy_setopt(handle, option, value)
Definition: typecheck-gcc.h:41
#define TEST_ERR_MAJOR_BAD
Definition: test.h:85
char * libtest_arg2
Definition: first.c:75
static int counter[MAX_EASY_HANDLES]
#define curl_easy_getinfo(handle, info, arg)
#define printf
Definition: curl_printf.h:40
CURL_EXTERN CURL * curl_easy_init(void)
Definition: easy.c:343
curlsocktype
Definition: curl.h:360
CURL_EXTERN void curl_easy_cleanup(CURL *curl)
int test(char *URL)
Definition: lib500.c:60
Definition: curl.h:455
char * libtest_arg3
Definition: first.c:76
CURL_EXTERN CURLcode curl_global_init(long flags)
curl_global_init() globally initializes curl given a bitwise set of the different features of what to...
Definition: easy.c:271
int socktype
Definition: curl.h:379
void CURL
Definition: curl.h:102
#define fprintf
Definition: curl_printf.h:41
CURL_EXTERN void curl_global_cleanup(void)
curl_global_cleanup() globally cleanups curl, uses the value of "init_flags" to determine what needs ...
Definition: easy.c:312
#define CURL_GLOBAL_ALL
Definition: curl.h:2519
struct libtest_trace_cfg libtest_debug_config
Definition: testtrace.c:28
int curl_socket_t
Definition: curl.h:130
static CURL * curl
Definition: sessioninfo.c:35
CURL_EXTERN CURLcode curl_easy_perform(CURL *curl)


rc_tagdetect_client
Author(s): Monika Florek-Jasinska , Raphael Schaller
autogenerated on Sat Feb 13 2021 03:42:15