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