lib530.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 "testutil.h"
25 #include "warnless.h"
26 #include "memdebug.h"
27 
28 #define TEST_HANG_TIMEOUT 60 * 1000
29 
30 #define NUM_HANDLES 4
31 
32 int test(char *URL)
33 {
34  int res = 0;
36  int running;
37  CURLM *m = NULL;
38  int i;
39  char target_url[256];
40  int handles_added = 0;
41 
42  for(i = 0; i < NUM_HANDLES; i++)
43  curl[i] = NULL;
44 
46 
48 
49  multi_init(m);
50 
51  /* get NUM_HANDLES easy handles */
52  for(i = 0; i < NUM_HANDLES; i++) {
53  /* get an easy handle */
54  easy_init(curl[i]);
55  /* specify target */
56  snprintf(target_url, sizeof(target_url), "%s%04i", URL, i + 1);
57  target_url[sizeof(target_url) - 1] = '\0';
58  easy_setopt(curl[i], CURLOPT_URL, target_url);
59  /* go verbose */
60  easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
61  /* include headers */
62  easy_setopt(curl[i], CURLOPT_HEADER, 1L);
63  }
64 
65  /* Add the first handle to multi. We do this to let libcurl detect
66  that the server can do pipelining. The rest of the handles will be
67  added later. */
68  multi_add_handle(m, curl[handles_added++]);
69 
70  multi_setopt(m, CURLMOPT_PIPELINING, 1L);
71 
72  fprintf(stderr, "Start at URL 0\n");
73 
74  for(;;) {
75  struct timeval interval;
76  fd_set rd, wr, exc;
77  int maxfd = -99;
78 
79  interval.tv_sec = 1;
80  interval.tv_usec = 0;
81 
82  multi_perform(m, &running);
83 
85 
86  if(!running) {
87  if(handles_added >= NUM_HANDLES)
88  break; /* done */
89 
90  /* Add the rest of the handles now that the first handle has completed
91  its request. */
92  while(handles_added < NUM_HANDLES)
93  multi_add_handle(m, curl[handles_added++]);
94  }
95 
96  FD_ZERO(&rd);
97  FD_ZERO(&wr);
98  FD_ZERO(&exc);
99 
100  multi_fdset(m, &rd, &wr, &exc, &maxfd);
101 
102  /* At this point, maxfd is guaranteed to be greater or equal than -1. */
103 
104  select_test(maxfd + 1, &rd, &wr, &exc, &interval);
105 
107  }
108 
109 test_cleanup:
110 
111  /* proper cleanup sequence - type PB */
112 
113  for(i = 0; i < NUM_HANDLES; i++) {
114  curl_multi_remove_handle(m, curl[i]);
115  curl_easy_cleanup(curl[i]);
116  }
117 
120 
121  return res;
122 }
#define select_test(A, B, C, D, E)
Definition: test.h:378
#define global_init(A)
Definition: test.h:431
#define easy_setopt(A, B, C)
Definition: test.h:190
#define multi_add_handle(A, B)
Definition: test.h:238
static int res
unsigned int i
Definition: unit1303.c:79
#define abort_on_test_timeout()
Definition: test.h:404
#define easy_init(A)
Definition: test.h:145
#define multi_setopt(A, B, C)
Definition: test.h:214
#define multi_fdset(A, B, C, D, E)
Definition: test.h:323
CURL_EXTERN void curl_easy_cleanup(CURL *curl)
int test(char *URL)
Definition: lib530.c:32
#define NUM_HANDLES
Definition: lib530.c:30
#define multi_perform(A, B)
Definition: test.h:293
CURL_EXTERN CURLMcode curl_multi_remove_handle(CURLM *multi_handle, CURL *curl_handle)
#define multi_init(A)
Definition: test.h:166
void CURLM
Definition: multi.h:58
void CURL
Definition: curl.h:102
#define fprintf
Definition: curl_printf.h:41
#define snprintf
Definition: curl_printf.h:42
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
static CURL * curl
Definition: sessioninfo.c:35
#define start_test_timing()
Definition: test.h:383
CURL_EXTERN CURLMcode curl_multi_cleanup(CURLM *multi_handle)


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