lib573.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2011, 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 http://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. #define TEST_HANG_TIMEOUT 60 * 1000
  27. /*
  28. * Get a single URL without select().
  29. */
  30. int test(char *URL)
  31. {
  32. CURL *c = NULL;
  33. CURLM *m = NULL;
  34. int res = 0;
  35. int running = 1;
  36. double connect_time = 0.0;
  37. double dbl_epsilon;
  38. dbl_epsilon = 1.0;
  39. do {
  40. dbl_epsilon /= 2.0;
  41. } while ((double)(1.0 + (dbl_epsilon/2.0)) > (double)1.0);
  42. start_test_timing();
  43. global_init(CURL_GLOBAL_ALL);
  44. easy_init(c);
  45. easy_setopt(c, CURLOPT_HEADER, 1L);
  46. easy_setopt(c, CURLOPT_URL, URL);
  47. multi_init(m);
  48. multi_add_handle(m, c);
  49. while (running) {
  50. struct timeval timeout;
  51. fd_set fdread, fdwrite, fdexcep;
  52. int maxfd = -99;
  53. timeout.tv_sec = 0;
  54. timeout.tv_usec = 100000L; /* 100 ms */
  55. multi_perform(m, &running);
  56. abort_on_test_timeout();
  57. if(!running)
  58. break; /* done */
  59. FD_ZERO(&fdread);
  60. FD_ZERO(&fdwrite);
  61. FD_ZERO(&fdexcep);
  62. multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
  63. /* At this point, maxfd is guaranteed to be greater or equal than -1. */
  64. select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
  65. abort_on_test_timeout();
  66. }
  67. curl_easy_getinfo(c, CURLINFO_CONNECT_TIME, &connect_time);
  68. if (connect_time < dbl_epsilon) {
  69. fprintf(stderr, "connect time is < epsilon\n");
  70. res = TEST_ERR_MAJOR_BAD;
  71. }
  72. test_cleanup:
  73. /* proper cleanup sequence - type PA */
  74. curl_multi_remove_handle(m, c);
  75. curl_multi_cleanup(m);
  76. curl_easy_cleanup(c);
  77. curl_global_cleanup();
  78. return res;
  79. }