lib1905.c 2.5 KB

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