lib530.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. #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. for(i=0; i < NUM_HANDLES; i++)
  37. curl[i] = NULL;
  38. start_test_timing();
  39. global_init(CURL_GLOBAL_ALL);
  40. multi_init(m);
  41. /* get NUM_HANDLES easy handles */
  42. for(i=0; i < NUM_HANDLES; i++) {
  43. /* get an easy handle */
  44. easy_init(curl[i]);
  45. /* specify target */
  46. sprintf(target_url, "%s%04i", URL, i + 1);
  47. target_url[sizeof(target_url) - 1] = '\0';
  48. easy_setopt(curl[i], CURLOPT_URL, target_url);
  49. /* go verbose */
  50. easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
  51. /* include headers */
  52. easy_setopt(curl[i], CURLOPT_HEADER, 1L);
  53. /* add handle to multi */
  54. multi_add_handle(m, curl[i]);
  55. }
  56. multi_setopt(m, CURLMOPT_PIPELINING, 1L);
  57. fprintf(stderr, "Start at URL 0\n");
  58. for(;;) {
  59. struct timeval interval;
  60. fd_set rd, wr, exc;
  61. int maxfd = -99;
  62. interval.tv_sec = 1;
  63. interval.tv_usec = 0;
  64. multi_perform(m, &running);
  65. abort_on_test_timeout();
  66. if(!running)
  67. break; /* done */
  68. FD_ZERO(&rd);
  69. FD_ZERO(&wr);
  70. FD_ZERO(&exc);
  71. multi_fdset(m, &rd, &wr, &exc, &maxfd);
  72. /* At this point, maxfd is guaranteed to be greater or equal than -1. */
  73. select_test(maxfd+1, &rd, &wr, &exc, &interval);
  74. abort_on_test_timeout();
  75. }
  76. test_cleanup:
  77. /* proper cleanup sequence - type PB */
  78. for(i=0; i < NUM_HANDLES; i++) {
  79. curl_multi_remove_handle(m, curl[i]);
  80. curl_easy_cleanup(curl[i]);
  81. }
  82. curl_multi_cleanup(m);
  83. curl_global_cleanup();
  84. return res;
  85. }