lib2404.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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;
  40. char *port = libtest_arg3;
  41. char *address = libtest_arg2;
  42. (void)URL;
  43. msnprintf(dnsentry, sizeof(dnsentry), "localhost:%s:%s",
  44. port, address);
  45. printf("%s\n", dnsentry);
  46. slist = curl_slist_append(slist, dnsentry);
  47. if(!slist) {
  48. fprintf(stderr, "curl_slist_append() failed\n");
  49. goto test_cleanup;
  50. }
  51. start_test_timing();
  52. global_init(CURL_GLOBAL_ALL);
  53. multi_init(m);
  54. multi_setopt(m, CURLMOPT_MAXCONNECTS, 1L);
  55. /* get NUM_HANDLES easy handles */
  56. for(i = 0; i < NUM_HANDLES; i++) {
  57. /* get an easy handle */
  58. easy_init(curl[i]);
  59. /* specify target */
  60. msnprintf(target_url, sizeof(target_url),
  61. "https://localhost:%s/path/2404%04i",
  62. port, i + 1);
  63. target_url[sizeof(target_url) - 1] = '\0';
  64. easy_setopt(curl[i], CURLOPT_URL, target_url);
  65. /* go http2 */
  66. easy_setopt(curl[i], CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
  67. /* no peer verify */
  68. easy_setopt(curl[i], CURLOPT_SSL_VERIFYPEER, 0L);
  69. easy_setopt(curl[i], CURLOPT_SSL_VERIFYHOST, 0L);
  70. /* wait for first connection established to see if we can share it */
  71. easy_setopt(curl[i], CURLOPT_PIPEWAIT, 1L);
  72. /* go verbose */
  73. easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
  74. /* include headers */
  75. easy_setopt(curl[i], CURLOPT_HEADER, 1L);
  76. easy_setopt(curl[i], CURLOPT_RESOLVE, slist);
  77. easy_setopt(curl[i], CURLOPT_STREAM_WEIGHT, (long)128 + i);
  78. }
  79. fprintf(stderr, "Start at URL 0\n");
  80. for(i = 0; i < NUM_HANDLES; i++) {
  81. /* add handle to multi */
  82. multi_add_handle(m, curl[i]);
  83. for(;;) {
  84. struct timeval interval;
  85. fd_set rd, wr, exc;
  86. int maxfd = -99;
  87. interval.tv_sec = 1;
  88. interval.tv_usec = 0;
  89. multi_perform(m, &running);
  90. abort_on_test_timeout();
  91. if(!running)
  92. break; /* done */
  93. FD_ZERO(&rd);
  94. FD_ZERO(&wr);
  95. FD_ZERO(&exc);
  96. multi_fdset(m, &rd, &wr, &exc, &maxfd);
  97. /* At this point, maxfd is guaranteed to be greater or equal than -1. */
  98. select_test(maxfd + 1, &rd, &wr, &exc, &interval);
  99. abort_on_test_timeout();
  100. }
  101. wait_ms(1); /* to ensure different end times */
  102. }
  103. test_cleanup:
  104. /* proper cleanup sequence - type PB */
  105. for(i = 0; i < NUM_HANDLES; i++) {
  106. curl_multi_remove_handle(m, curl[i]);
  107. curl_easy_cleanup(curl[i]);
  108. }
  109. curl_slist_free_all(slist);
  110. curl_multi_cleanup(m);
  111. curl_global_cleanup();
  112. return res;
  113. }