Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/curl/tests/libtest/lib1507.c
2649 views
1
/***************************************************************************
2
* _ _ ____ _
3
* Project ___| | | | _ \| |
4
* / __| | | | |_) | |
5
* | (__| |_| | _ <| |___
6
* \___|\___/|_| \_\_____|
7
*
8
* Copyright (C) Daniel Stenberg, <[email protected]>, 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 "first.h"
25
26
#include "memdebug.h"
27
28
static size_t t1507_read_cb(char *ptr, size_t size, size_t nmemb, void *userp)
29
{
30
(void)ptr;
31
(void)size;
32
(void)nmemb;
33
(void)userp;
34
return CURL_READFUNC_ABORT;
35
}
36
37
static CURLcode test_lib1507(const char *URL)
38
{
39
static const int MULTI_PERFORM_HANG_TIMEOUT = 60 * 1000;
40
41
CURLcode res = CURLE_OK;
42
CURL *curl = NULL;
43
CURLM *multi = NULL;
44
int still_running = 1;
45
struct curltime mp_start;
46
struct curl_slist *rcpt_list = NULL;
47
48
curl_global_init(CURL_GLOBAL_DEFAULT);
49
50
easy_init(curl);
51
52
multi_init(multi);
53
54
rcpt_list = curl_slist_append(rcpt_list, "<[email protected]>");
55
#if 0
56
/* more addresses can be added here */
57
rcpt_list = curl_slist_append(rcpt_list, "<[email protected]>");
58
#endif
59
curl_easy_setopt(curl, CURLOPT_URL, URL);
60
#if 0
61
curl_easy_setopt(curl, CURLOPT_USERNAME, "[email protected]");
62
curl_easy_setopt(curl, CURLOPT_PASSWORD, "123qwerty");
63
#endif
64
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
65
curl_easy_setopt(curl, CURLOPT_READFUNCTION, t1507_read_cb);
66
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, "<[email protected]>");
67
curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, rcpt_list);
68
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
69
multi_add_handle(multi, curl);
70
71
mp_start = curlx_now();
72
73
/* we start some action by calling perform right away */
74
curl_multi_perform(multi, &still_running);
75
76
while(still_running) {
77
struct timeval timeout;
78
int rc; /* select() return code */
79
80
fd_set fdread;
81
fd_set fdwrite;
82
fd_set fdexcep;
83
int maxfd = -1;
84
85
long curl_timeo = -1;
86
87
FD_ZERO(&fdread);
88
FD_ZERO(&fdwrite);
89
FD_ZERO(&fdexcep);
90
91
/* set a suitable timeout to play around with */
92
timeout.tv_sec = 1;
93
timeout.tv_usec = 0;
94
95
curl_multi_timeout(multi, &curl_timeo);
96
if(curl_timeo >= 0) {
97
curlx_mstotv(&timeout, curl_timeo);
98
if(timeout.tv_sec > 1) {
99
timeout.tv_sec = 1;
100
timeout.tv_usec = 0;
101
}
102
}
103
104
/* get file descriptors from the transfers */
105
curl_multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
106
107
/* In a real-world program you OF COURSE check the return code of the
108
function calls. On success, the value of maxfd is guaranteed to be
109
greater or equal than -1. We call select(maxfd + 1, ...), specially in
110
case of (maxfd == -1), we call select(0, ...), which is basically equal
111
to sleep. */
112
113
rc = select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
114
115
if(curlx_timediff(curlx_now(), mp_start) > MULTI_PERFORM_HANG_TIMEOUT) {
116
curl_mfprintf(stderr, "ABORTING TEST, since it seems "
117
"that it would have run forever.\n");
118
break;
119
}
120
121
switch(rc) {
122
case -1:
123
/* select error */
124
break;
125
case 0: /* timeout */
126
default: /* action */
127
curl_multi_perform(multi, &still_running);
128
break;
129
}
130
}
131
132
test_cleanup:
133
134
curl_slist_free_all(rcpt_list);
135
curl_multi_remove_handle(multi, curl);
136
curl_multi_cleanup(multi);
137
curl_easy_cleanup(curl);
138
curl_global_cleanup();
139
140
return res;
141
}
142
143