2
0

lib1506.c 3.5 KB

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