lib573.c 2.8 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.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 "testtrace.h"
  24. #include "testutil.h"
  25. #include "warnless.h"
  26. #include "memdebug.h"
  27. #define TEST_HANG_TIMEOUT 60 * 1000
  28. /*
  29. * Get a single URL without select().
  30. */
  31. int test(char *URL)
  32. {
  33. CURL *c = NULL;
  34. CURLM *m = NULL;
  35. int res = 0;
  36. int running = 1;
  37. double connect_time = 0.0;
  38. double dbl_epsilon;
  39. dbl_epsilon = 1.0;
  40. do {
  41. dbl_epsilon /= 2.0;
  42. } while((double)(1.0 + (dbl_epsilon/2.0)) > (double)1.0);
  43. start_test_timing();
  44. global_init(CURL_GLOBAL_ALL);
  45. easy_init(c);
  46. easy_setopt(c, CURLOPT_HEADER, 1L);
  47. easy_setopt(c, CURLOPT_URL, URL);
  48. libtest_debug_config.nohex = 1;
  49. libtest_debug_config.tracetime = 1;
  50. easy_setopt(c, CURLOPT_DEBUGDATA, &libtest_debug_config);
  51. easy_setopt(c, CURLOPT_DEBUGFUNCTION, libtest_debug_cb);
  52. easy_setopt(c, CURLOPT_VERBOSE, 1L);
  53. multi_init(m);
  54. multi_add_handle(m, c);
  55. while(running) {
  56. struct timeval timeout;
  57. fd_set fdread, fdwrite, fdexcep;
  58. int maxfd = -99;
  59. timeout.tv_sec = 0;
  60. timeout.tv_usec = 100000L; /* 100 ms */
  61. multi_perform(m, &running);
  62. abort_on_test_timeout();
  63. if(!running)
  64. break; /* done */
  65. FD_ZERO(&fdread);
  66. FD_ZERO(&fdwrite);
  67. FD_ZERO(&fdexcep);
  68. multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
  69. /* At this point, maxfd is guaranteed to be greater or equal than -1. */
  70. select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
  71. abort_on_test_timeout();
  72. }
  73. curl_easy_getinfo(c, CURLINFO_CONNECT_TIME, &connect_time);
  74. if(connect_time < dbl_epsilon) {
  75. fprintf(stderr, "connect time %e is < epsilon %e\n",
  76. connect_time, dbl_epsilon);
  77. res = TEST_ERR_MAJOR_BAD;
  78. }
  79. test_cleanup:
  80. /* proper cleanup sequence - type PA */
  81. curl_multi_remove_handle(m, c);
  82. curl_multi_cleanup(m);
  83. curl_easy_cleanup(c);
  84. curl_global_cleanup();
  85. return res;
  86. }