lib1506.c
Go to the documentation of this file.
1 /***************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 2013, 2017, Linus Nielsen Feltzing <linus@haxx.se>
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;
35  CURL *curl[NUM_HANDLES] = {0};
36  int running;
37  CURLM *m = NULL;
38  int i;
39  char target_url[256];
40  char dnsentry[256];
41  struct curl_slist *slist = NULL, *slist2;
42  char *port = libtest_arg3;
43  char *address = libtest_arg2;
44 
45  (void)URL;
46 
47  /* Create fake DNS entries for serverX.example.com for all handles */
48  for(i = 0; i < NUM_HANDLES; i++) {
49  snprintf(dnsentry, sizeof(dnsentry), "server%d.example.com:%s:%s",
50  i + 1, port, address);
51  printf("%s\n", dnsentry);
52  slist2 = curl_slist_append(slist, dnsentry);
53  if(!slist2) {
54  fprintf(stderr, "curl_slist_append() failed\n");
55  goto test_cleanup;
56  }
57  slist = slist2;
58  }
59 
61 
63 
64  multi_init(m);
65 
66  multi_setopt(m, CURLMOPT_MAXCONNECTS, 3L);
67 
68  /* get NUM_HANDLES easy handles */
69  for(i = 0; i < NUM_HANDLES; i++) {
70  /* get an easy handle */
71  easy_init(curl[i]);
72  /* specify target */
73  snprintf(target_url, sizeof(target_url),
74  "http://server%d.example.com:%s/path/1506%04i",
75  i + 1, port, i + 1);
76  target_url[sizeof(target_url) - 1] = '\0';
77  easy_setopt(curl[i], CURLOPT_URL, target_url);
78  /* go verbose */
79  easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
80  /* include headers */
81  easy_setopt(curl[i], CURLOPT_HEADER, 1L);
82 
83  easy_setopt(curl[i], CURLOPT_RESOLVE, slist);
84  }
85 
86  fprintf(stderr, "Start at URL 0\n");
87 
88  for(i = 0; i < NUM_HANDLES; i++) {
89  /* add handle to multi */
90  multi_add_handle(m, curl[i]);
91 
92  for(;;) {
93  struct timeval interval;
94  fd_set rd, wr, exc;
95  int maxfd = -99;
96 
97  interval.tv_sec = 1;
98  interval.tv_usec = 0;
99 
100  multi_perform(m, &running);
101 
103 
104  if(!running)
105  break; /* done */
106 
107  FD_ZERO(&rd);
108  FD_ZERO(&wr);
109  FD_ZERO(&exc);
110 
111  multi_fdset(m, &rd, &wr, &exc, &maxfd);
112 
113  /* At this point, maxfd is guaranteed to be greater or equal than -1. */
114 
115  select_test(maxfd + 1, &rd, &wr, &exc, &interval);
116 
118  }
119  wait_ms(1); /* to ensure different end times */
120  }
121 
122 test_cleanup:
123 
124  /* proper cleanup sequence - type PB */
125 
126  for(i = 0; i < NUM_HANDLES; i++) {
127  curl_multi_remove_handle(m, curl[i]);
128  curl_easy_cleanup(curl[i]);
129  }
130 
131  curl_slist_free_all(slist);
132 
135 
136  return res;
137 }
#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
void wait_ms(int ms)
Definition: first.c:66
static int res
unsigned int i
Definition: unit1303.c:79
#define abort_on_test_timeout()
Definition: test.h:404
char * libtest_arg2
Definition: first.c:75
CURL_EXTERN struct curl_slist * curl_slist_append(struct curl_slist *, const char *)
Definition: slist.c:89
#define printf
Definition: curl_printf.h:40
#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)
static unsigned short port
Definition: sockfilt.c:137
#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
char * libtest_arg3
Definition: first.c:76
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
CURL_EXTERN void curl_slist_free_all(struct curl_slist *)
Definition: slist.c:129
#define NUM_HANDLES
Definition: lib1506.c:30
#define start_test_timing()
Definition: test.h:383
int test(char *URL)
Definition: lib1506.c:32
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