lib536.c
Go to the documentation of this file.
1 /***************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2011, 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 <fcntl.h>
25 
26 #include "testutil.h"
27 #include "warnless.h"
28 #include "memdebug.h"
29 
30 #define TEST_HANG_TIMEOUT 60 * 1000
31 
32 static int perform(CURLM *multi)
33 {
34  int handles;
35  fd_set fdread, fdwrite, fdexcep;
36  int res = 0;
37 
38  for(;;) {
39  struct timeval interval;
40  int maxfd = -99;
41 
42  interval.tv_sec = 0;
43  interval.tv_usec = 100000L; /* 100 ms */
44 
45  res_multi_perform(multi, &handles);
46  if(res)
47  return res;
48 
50  if(res)
51  return res;
52 
53  if(!handles)
54  break; /* done */
55 
56  FD_ZERO(&fdread);
57  FD_ZERO(&fdwrite);
58  FD_ZERO(&fdexcep);
59 
60  res_multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
61  if(res)
62  return res;
63 
64  /* At this point, maxfd is guaranteed to be greater or equal than -1. */
65 
66  res_select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &interval);
67  if(res)
68  return res;
69 
71  if(res)
72  return res;
73  }
74 
75  return 0; /* success */
76 }
77 
78 int test(char *URL)
79 {
80  CURLM *multi = NULL;
81  CURL *easy = NULL;
82  int res = 0;
83 
85 
87 
88  multi_init(multi);
89 
90  easy_init(easy);
91 
92  multi_setopt(multi, CURLMOPT_PIPELINING, 1L);
93 
94  easy_setopt(easy, CURLOPT_WRITEFUNCTION, fwrite);
95  easy_setopt(easy, CURLOPT_FAILONERROR, 1L);
96  easy_setopt(easy, CURLOPT_URL, URL);
97 
98  res_multi_add_handle(multi, easy);
99  if(res) {
100  printf("curl_multi_add_handle() 1 failed\n");
101  goto test_cleanup;
102  }
103 
104  res = perform(multi);
105  if(res) {
106  printf("retrieve 1 failed\n");
107  goto test_cleanup;
108  }
109 
110  curl_multi_remove_handle(multi, easy);
111 
112  curl_easy_reset(easy);
113 
114  easy_setopt(easy, CURLOPT_FAILONERROR, 1L);
115  easy_setopt(easy, CURLOPT_URL, libtest_arg2);
116 
117  res_multi_add_handle(multi, easy);
118  if(res) {
119  printf("curl_multi_add_handle() 2 failed\n");
120  goto test_cleanup;
121  }
122 
123  res = perform(multi);
124  if(res) {
125  printf("retrieve 2 failed\n");
126  goto test_cleanup;
127  }
128 
129  curl_multi_remove_handle(multi, easy);
130 
131 test_cleanup:
132 
133  /* undocumented cleanup sequence - type UB */
134 
135  curl_easy_cleanup(easy);
136  curl_multi_cleanup(multi);
138 
139  printf("Finished!\n");
140 
141  return res;
142 }
#define res_multi_add_handle(A, B)
Definition: test.h:229
CURL_EXTERN void curl_easy_reset(CURL *curl)
#define global_init(A)
Definition: test.h:431
#define easy_setopt(A, B, C)
Definition: test.h:190
#define res_multi_perform(A, B)
Definition: test.h:284
static int res
static int perform(CURLM *multi)
Definition: lib536.c:32
char * libtest_arg2
Definition: first.c:75
#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
CURL_EXTERN void curl_easy_cleanup(CURL *curl)
int test(char *URL)
Definition: lib536.c:78
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
#define res_select_test(A, B, C, D, E)
Definition: test.h:369
#define res_test_timedout()
Definition: test.h:395
void CURL
Definition: curl.h:102
static CURL * handles[MAX_URLS]
Definition: lib1900.c:34
static CURL * easy[MAX_EASY_HANDLES]
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
#define start_test_timing()
Definition: test.h:383
size_t fwrite(const void *, size_t, size_t, FILE *)
#define res_multi_fdset(A, B, C, D, E)
Definition: test.h:314
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