lib560.c 3.2 KB

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