2
0

lib1905.c 2.6 KB

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