• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 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.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  * SPDX-License-Identifier: curl
22  *
23  ***************************************************************************/
24 #include "test.h"
25 
26 #include "testutil.h"
27 #include "warnless.h"
28 #include "memdebug.h"
29 
30 #define TEST_HANG_TIMEOUT 60 * 1000
31 
xferinfo(void * p,curl_off_t dltotal,curl_off_t dlnow,curl_off_t ultotal,curl_off_t ulnow)32 static int xferinfo(void *p,
33                     curl_off_t dltotal, curl_off_t dlnow,
34                     curl_off_t ultotal, curl_off_t ulnow)
35 {
36   (void)p;
37   (void)dlnow;
38   (void)dltotal;
39   (void)ulnow;
40   (void)ultotal;
41   fprintf(stderr, "xferinfo fail!\n");
42   return 1; /* fail as fast as we can */
43 }
44 
test(char * URL)45 int test(char *URL)
46 {
47   CURL *curls = NULL;
48   CURLM *multi = NULL;
49   int still_running;
50   int i = 0;
51   int res = 0;
52   curl_mimepart *field = NULL;
53   curl_mime *mime = NULL;
54   int counter = 1;
55 
56   start_test_timing();
57 
58   global_init(CURL_GLOBAL_ALL);
59 
60   multi_init(multi);
61 
62   easy_init(curls);
63 
64   mime = curl_mime_init(curls);
65   field = curl_mime_addpart(mime);
66   curl_mime_name(field, "name");
67   curl_mime_data(field, "value", CURL_ZERO_TERMINATED);
68 
69   easy_setopt(curls, CURLOPT_URL, URL);
70   easy_setopt(curls, CURLOPT_HEADER, 1L);
71   easy_setopt(curls, CURLOPT_VERBOSE, 1L);
72   easy_setopt(curls, CURLOPT_MIMEPOST, mime);
73   easy_setopt(curls, CURLOPT_USERPWD, "u:s");
74   easy_setopt(curls, CURLOPT_XFERINFOFUNCTION, xferinfo);
75   easy_setopt(curls, CURLOPT_NOPROGRESS, 1L);
76 
77   multi_add_handle(multi, curls);
78 
79   multi_perform(multi, &still_running);
80 
81   abort_on_test_timeout();
82 
83   while(still_running && counter--) {
84     int num;
85     res = curl_multi_wait(multi, NULL, 0, TEST_HANG_TIMEOUT, &num);
86     if(res != CURLM_OK) {
87       printf("curl_multi_wait() returned %d\n", res);
88       res = TEST_ERR_MAJOR_BAD;
89       goto test_cleanup;
90     }
91 
92     abort_on_test_timeout();
93 
94     multi_perform(multi, &still_running);
95 
96     abort_on_test_timeout();
97   }
98 
99 test_cleanup:
100 
101   curl_mime_free(mime);
102   curl_multi_remove_handle(multi, curls);
103   curl_multi_cleanup(multi);
104   curl_easy_cleanup(curls);
105   curl_global_cleanup();
106 
107   if(res)
108     i = res;
109 
110   return i; /* return the final return code */
111 }
112