lib536.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 <fcntl.h>
  24. #include "testutil.h"
  25. #include "warnless.h"
  26. #include "memdebug.h"
  27. #define TEST_HANG_TIMEOUT 60 * 1000
  28. static int perform(CURLM *multi)
  29. {
  30. int handles;
  31. fd_set fdread, fdwrite, fdexcep;
  32. int res = 0;
  33. for(;;) {
  34. struct timeval interval;
  35. int maxfd = -99;
  36. interval.tv_sec = 0;
  37. interval.tv_usec = 100000L; /* 100 ms */
  38. res_multi_perform(multi, &handles);
  39. if(res)
  40. return res;
  41. res_test_timedout();
  42. if(res)
  43. return res;
  44. if(!handles)
  45. break; /* done */
  46. FD_ZERO(&fdread);
  47. FD_ZERO(&fdwrite);
  48. FD_ZERO(&fdexcep);
  49. res_multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
  50. if(res)
  51. return res;
  52. /* At this point, maxfd is guaranteed to be greater or equal than -1. */
  53. res_select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &interval);
  54. if(res)
  55. return res;
  56. res_test_timedout();
  57. if(res)
  58. return res;
  59. }
  60. return 0; /* success */
  61. }
  62. int test(char *URL)
  63. {
  64. CURLM *multi = NULL;
  65. CURL *easy = NULL;
  66. int res = 0;
  67. start_test_timing();
  68. global_init(CURL_GLOBAL_ALL);
  69. multi_init(multi);
  70. easy_init(easy);
  71. multi_setopt(multi, CURLMOPT_PIPELINING, 1L);
  72. easy_setopt(easy, CURLOPT_WRITEFUNCTION, fwrite);
  73. easy_setopt(easy, CURLOPT_FAILONERROR, 1L);
  74. easy_setopt(easy, CURLOPT_URL, URL);
  75. res_multi_add_handle(multi, easy);
  76. if(res) {
  77. printf("curl_multi_add_handle() 1 failed\n");
  78. goto test_cleanup;
  79. }
  80. res = perform(multi);
  81. if(res) {
  82. printf("retrieve 1 failed\n");
  83. goto test_cleanup;
  84. }
  85. curl_multi_remove_handle(multi, easy);
  86. curl_easy_reset(easy);
  87. easy_setopt(easy, CURLOPT_FAILONERROR, 1L);
  88. easy_setopt(easy, CURLOPT_URL, libtest_arg2);
  89. res_multi_add_handle(multi, easy);
  90. if(res) {
  91. printf("curl_multi_add_handle() 2 failed\n");
  92. goto test_cleanup;
  93. }
  94. res = perform(multi);
  95. if(res) {
  96. printf("retrieve 2 failed\n");
  97. goto test_cleanup;
  98. }
  99. curl_multi_remove_handle(multi, easy);
  100. test_cleanup:
  101. /* undocumented cleanup sequence - type UB */
  102. curl_easy_cleanup(easy);
  103. curl_multi_cleanup(multi);
  104. curl_global_cleanup();
  105. printf("Finished!\n");
  106. return res;
  107. }