lib2402.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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/2402%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. }
  78. fprintf(stderr, "Start at URL 0\n");
  79. for(i = 0; i < NUM_HANDLES; i++) {
  80. /* add handle to multi */
  81. multi_add_handle(m, curl[i]);
  82. for(;;) {
  83. struct timeval interval;
  84. fd_set rd, wr, exc;
  85. int maxfd = -99;
  86. interval.tv_sec = 1;
  87. interval.tv_usec = 0;
  88. multi_perform(m, &running);
  89. abort_on_test_timeout();
  90. if(!running)
  91. break; /* done */
  92. FD_ZERO(&rd);
  93. FD_ZERO(&wr);
  94. FD_ZERO(&exc);
  95. multi_fdset(m, &rd, &wr, &exc, &maxfd);
  96. /* At this point, maxfd is guaranteed to be greater or equal than -1. */
  97. select_test(maxfd + 1, &rd, &wr, &exc, &interval);
  98. abort_on_test_timeout();
  99. }
  100. wait_ms(1); /* to ensure different end times */
  101. }
  102. test_cleanup:
  103. /* proper cleanup sequence - type PB */
  104. for(i = 0; i < NUM_HANDLES; i++) {
  105. curl_multi_remove_handle(m, curl[i]);
  106. curl_easy_cleanup(curl[i]);
  107. }
  108. curl_slist_free_all(slist);
  109. curl_multi_cleanup(m);
  110. curl_global_cleanup();
  111. return res;
  112. }