lib1905.c (2571B)
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 "first.h" 25 26 #include "memdebug.h" 27 28 static CURLcode test_lib1905(char *URL) 29 { 30 CURLSH *sh = NULL; 31 CURL *ch = NULL; 32 int unfinished; 33 CURLM *cm; 34 35 curl_global_init(CURL_GLOBAL_ALL); 36 37 cm = curl_multi_init(); 38 if(!cm) { 39 curl_global_cleanup(); 40 return TEST_ERR_MULTI; 41 } 42 sh = curl_share_init(); 43 if(!sh) 44 goto cleanup; 45 46 curl_share_setopt(sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE); 47 curl_share_setopt(sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE); 48 49 ch = curl_easy_init(); 50 if(!ch) 51 goto cleanup; 52 53 curl_easy_setopt(ch, CURLOPT_SHARE, sh); 54 curl_easy_setopt(ch, CURLOPT_URL, URL); 55 curl_easy_setopt(ch, CURLOPT_COOKIEFILE, libtest_arg2); 56 curl_easy_setopt(ch, CURLOPT_COOKIEJAR, libtest_arg2); 57 58 curl_multi_add_handle(cm, ch); 59 60 unfinished = 1; 61 while(unfinished) { 62 int MAX = 0; 63 long max_tout; 64 fd_set R, W, E; 65 struct timeval timeout; 66 67 FD_ZERO(&R); 68 FD_ZERO(&W); 69 FD_ZERO(&E); 70 curl_multi_perform(cm, &unfinished); 71 72 curl_multi_fdset(cm, &R, &W, &E, &MAX); 73 curl_multi_timeout(cm, &max_tout); 74 75 if(max_tout > 0) { 76 curlx_mstotv(&timeout, max_tout); 77 } 78 else { 79 timeout.tv_sec = 0; 80 timeout.tv_usec = 1000; 81 } 82 83 select(MAX + 1, &R, &W, &E, &timeout); 84 } 85 86 curl_easy_setopt(ch, CURLOPT_COOKIELIST, "FLUSH"); 87 curl_easy_setopt(ch, CURLOPT_SHARE, NULL); 88 89 curl_multi_remove_handle(cm, ch); 90 cleanup: 91 curl_easy_cleanup(ch); 92 curl_share_cleanup(sh); 93 curl_multi_cleanup(cm); 94 curl_global_cleanup(); 95 96 return CURLE_OK; 97 }