lib560.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2020, 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 "warnless.h"
  25. #include "memdebug.h"
  26. #define TEST_HANG_TIMEOUT 60 * 1000
  27. /*
  28. * Simply download a HTTPS file!
  29. *
  30. * This test was added after the HTTPS-using-multi-interface with OpenSSL
  31. * regression of 7.19.1 to hopefully prevent this embarrassing mistake from
  32. * appearing again... Unfortunately the bug wasn't triggered by this test,
  33. * which presumably is because the connect to a local server is too
  34. * fast/different compared to the real/distant servers we saw the bug happen
  35. * with.
  36. */
  37. int test(char *URL)
  38. {
  39. CURL *http_handle = NULL;
  40. CURLM *multi_handle = NULL;
  41. int res = 0;
  42. int still_running; /* keep number of running handles */
  43. start_test_timing();
  44. /*
  45. ** curl_global_init called indirectly from curl_easy_init.
  46. */
  47. easy_init(http_handle);
  48. /* set options */
  49. easy_setopt(http_handle, CURLOPT_URL, URL);
  50. easy_setopt(http_handle, CURLOPT_HEADER, 1L);
  51. easy_setopt(http_handle, CURLOPT_SSL_VERIFYPEER, 0L);
  52. easy_setopt(http_handle, CURLOPT_SSL_VERIFYHOST, 0L);
  53. /* init a multi stack */
  54. multi_init(multi_handle);
  55. /* add the individual transfers */
  56. multi_add_handle(multi_handle, http_handle);
  57. /* we start some action by calling perform right away */
  58. multi_perform(multi_handle, &still_running);
  59. abort_on_test_timeout();
  60. while(still_running) {
  61. struct timeval timeout;
  62. fd_set fdread;
  63. fd_set fdwrite;
  64. fd_set fdexcep;
  65. int maxfd = -99;
  66. FD_ZERO(&fdread);
  67. FD_ZERO(&fdwrite);
  68. FD_ZERO(&fdexcep);
  69. /* set a suitable timeout to play around with */
  70. timeout.tv_sec = 1;
  71. timeout.tv_usec = 0;
  72. /* get file descriptors from the transfers */
  73. multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
  74. /* At this point, maxfd is guaranteed to be greater or equal than -1. */
  75. select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
  76. abort_on_test_timeout();
  77. /* timeout or readable/writable sockets */
  78. multi_perform(multi_handle, &still_running);
  79. abort_on_test_timeout();
  80. }
  81. test_cleanup:
  82. /* undocumented cleanup sequence - type UA */
  83. curl_multi_cleanup(multi_handle);
  84. curl_easy_cleanup(http_handle);
  85. curl_global_cleanup();
  86. return res;
  87. }