2
0

lib1506.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) Linus Nielsen Feltzing <linus@haxx.se>
  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.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. * SPDX-License-Identifier: curl
  22. *
  23. ***************************************************************************/
  24. #include "test.h"
  25. #include "testutil.h"
  26. #include "warnless.h"
  27. #include "memdebug.h"
  28. #define TEST_HANG_TIMEOUT 60 * 1000
  29. #define NUM_HANDLES 4
  30. int test(char *URL)
  31. {
  32. int res = 0;
  33. CURL *curl[NUM_HANDLES] = {0};
  34. int running;
  35. CURLM *m = NULL;
  36. int i;
  37. char target_url[256];
  38. char dnsentry[256];
  39. struct curl_slist *slist = NULL, *slist2;
  40. char *port = libtest_arg3;
  41. char *address = libtest_arg2;
  42. (void)URL;
  43. /* Create fake DNS entries for serverX.example.com for all handles */
  44. for(i = 0; i < NUM_HANDLES; i++) {
  45. msnprintf(dnsentry, sizeof(dnsentry), "server%d.example.com:%s:%s",
  46. i + 1, port, address);
  47. printf("%s\n", dnsentry);
  48. slist2 = curl_slist_append(slist, dnsentry);
  49. if(!slist2) {
  50. fprintf(stderr, "curl_slist_append() failed\n");
  51. goto test_cleanup;
  52. }
  53. slist = slist2;
  54. }
  55. start_test_timing();
  56. global_init(CURL_GLOBAL_ALL);
  57. multi_init(m);
  58. multi_setopt(m, CURLMOPT_MAXCONNECTS, 3L);
  59. /* get NUM_HANDLES easy handles */
  60. for(i = 0; i < NUM_HANDLES; i++) {
  61. /* get an easy handle */
  62. easy_init(curl[i]);
  63. /* specify target */
  64. msnprintf(target_url, sizeof(target_url),
  65. "http://server%d.example.com:%s/path/1506%04i",
  66. i + 1, port, i + 1);
  67. target_url[sizeof(target_url) - 1] = '\0';
  68. easy_setopt(curl[i], CURLOPT_URL, target_url);
  69. /* go verbose */
  70. easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
  71. /* include headers */
  72. easy_setopt(curl[i], CURLOPT_HEADER, 1L);
  73. easy_setopt(curl[i], CURLOPT_RESOLVE, slist);
  74. }
  75. fprintf(stderr, "Start at URL 0\n");
  76. for(i = 0; i < NUM_HANDLES; i++) {
  77. /* add handle to multi */
  78. multi_add_handle(m, curl[i]);
  79. for(;;) {
  80. struct timeval interval;
  81. fd_set rd, wr, exc;
  82. int maxfd = -99;
  83. interval.tv_sec = 1;
  84. interval.tv_usec = 0;
  85. multi_perform(m, &running);
  86. abort_on_test_timeout();
  87. if(!running)
  88. break; /* done */
  89. FD_ZERO(&rd);
  90. FD_ZERO(&wr);
  91. FD_ZERO(&exc);
  92. multi_fdset(m, &rd, &wr, &exc, &maxfd);
  93. /* At this point, maxfd is guaranteed to be greater or equal than -1. */
  94. select_test(maxfd + 1, &rd, &wr, &exc, &interval);
  95. abort_on_test_timeout();
  96. }
  97. wait_ms(1); /* to ensure different end times */
  98. }
  99. test_cleanup:
  100. /* proper cleanup sequence - type PB */
  101. for(i = 0; i < NUM_HANDLES; i++) {
  102. curl_multi_remove_handle(m, curl[i]);
  103. curl_easy_cleanup(curl[i]);
  104. }
  105. curl_slist_free_all(slist);
  106. curl_multi_cleanup(m);
  107. curl_global_cleanup();
  108. return res;
  109. }