lib530.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2018, 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 "testutil.h"
  24. #include "warnless.h"
  25. #include "memdebug.h"
  26. #define TEST_HANG_TIMEOUT 60 * 1000
  27. #define NUM_HANDLES 4
  28. int test(char *URL)
  29. {
  30. int res = 0;
  31. CURL *curl[NUM_HANDLES];
  32. int running;
  33. CURLM *m = NULL;
  34. int i;
  35. char target_url[256];
  36. int handles_added = 0;
  37. for(i = 0; i < NUM_HANDLES; i++)
  38. curl[i] = NULL;
  39. start_test_timing();
  40. global_init(CURL_GLOBAL_ALL);
  41. multi_init(m);
  42. /* get NUM_HANDLES easy handles */
  43. for(i = 0; i < NUM_HANDLES; i++) {
  44. /* get an easy handle */
  45. easy_init(curl[i]);
  46. /* specify target */
  47. msnprintf(target_url, sizeof(target_url), "%s%04i", URL, i + 1);
  48. target_url[sizeof(target_url) - 1] = '\0';
  49. easy_setopt(curl[i], CURLOPT_URL, target_url);
  50. /* go verbose */
  51. easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
  52. /* include headers */
  53. easy_setopt(curl[i], CURLOPT_HEADER, 1L);
  54. }
  55. /* Add the first handle to multi. We do this to let libcurl detect
  56. that the server can do pipelining. The rest of the handles will be
  57. added later. */
  58. multi_add_handle(m, curl[handles_added++]);
  59. multi_setopt(m, CURLMOPT_PIPELINING, 1L);
  60. fprintf(stderr, "Start at URL 0\n");
  61. for(;;) {
  62. struct timeval interval;
  63. fd_set rd, wr, exc;
  64. int maxfd = -99;
  65. interval.tv_sec = 1;
  66. interval.tv_usec = 0;
  67. multi_perform(m, &running);
  68. abort_on_test_timeout();
  69. if(!running) {
  70. if(handles_added >= NUM_HANDLES)
  71. break; /* done */
  72. /* Add the rest of the handles now that the first handle has completed
  73. its request. */
  74. while(handles_added < NUM_HANDLES)
  75. multi_add_handle(m, curl[handles_added++]);
  76. }
  77. FD_ZERO(&rd);
  78. FD_ZERO(&wr);
  79. FD_ZERO(&exc);
  80. multi_fdset(m, &rd, &wr, &exc, &maxfd);
  81. /* At this point, maxfd is guaranteed to be greater or equal than -1. */
  82. select_test(maxfd + 1, &rd, &wr, &exc, &interval);
  83. abort_on_test_timeout();
  84. }
  85. test_cleanup:
  86. /* proper cleanup sequence - type PB */
  87. for(i = 0; i < NUM_HANDLES; i++) {
  88. curl_multi_remove_handle(m, curl[i]);
  89. curl_easy_cleanup(curl[i]);
  90. }
  91. curl_multi_cleanup(m);
  92. curl_global_cleanup();
  93. return res;
  94. }