2
0

lib1905.c 2.5 KB

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