1 /***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) 2019, 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
test(char * URL)28 int test(char *URL)
29 {
30 CURLM *cm = NULL;
31 CURLSH *sh = NULL;
32 CURL *ch = NULL;
33 int unfinished;
34
35 cm = curl_multi_init();
36 if(!cm)
37 return 1;
38 sh = curl_share_init();
39 if(!sh)
40 goto cleanup;
41
42 curl_share_setopt(sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
43 curl_share_setopt(sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
44
45 ch = curl_easy_init();
46 if(!ch)
47 goto cleanup;
48
49 curl_easy_setopt(ch, CURLOPT_SHARE, sh);
50 curl_easy_setopt(ch, CURLOPT_URL, URL);
51 curl_easy_setopt(ch, CURLOPT_COOKIEFILE, "log/cookies1905");
52 curl_easy_setopt(ch, CURLOPT_COOKIEJAR, "log/cookies1905");
53
54 curl_multi_add_handle(cm, ch);
55
56 unfinished = 1;
57 while(unfinished) {
58 int MAX = 0;
59 long max_tout;
60 fd_set R, W, E;
61 struct timeval timeout;
62
63 FD_ZERO(&R);
64 FD_ZERO(&W);
65 FD_ZERO(&E);
66 curl_multi_perform(cm, &unfinished);
67
68 curl_multi_fdset(cm, &R, &W, &E, &MAX);
69 curl_multi_timeout(cm, &max_tout);
70
71 if(max_tout > 0) {
72 timeout.tv_sec = max_tout / 1000;
73 timeout.tv_usec = (max_tout % 1000) * 1000;
74 }
75 else {
76 timeout.tv_sec = 0;
77 timeout.tv_usec = 1000;
78 }
79
80 select(MAX + 1, &R, &W, &E, &timeout);
81 }
82
83 curl_easy_setopt(ch, CURLOPT_COOKIELIST, "FLUSH");
84 curl_easy_setopt(ch, CURLOPT_SHARE, NULL);
85
86 curl_multi_remove_handle(cm, ch);
87 cleanup:
88 curl_easy_cleanup(ch);
89 curl_share_cleanup(sh);
90 curl_multi_cleanup(cm);
91
92 return 0;
93 }
94