2
0

lib2502.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 "testtrace.h"
  26. #include "testutil.h"
  27. #include "warnless.h"
  28. #include "memdebug.h"
  29. #define TEST_HANG_TIMEOUT 60 * 1000
  30. #define NUM_HANDLES 4
  31. CURLcode test(char *URL)
  32. {
  33. CURLcode res = CURLE_OK;
  34. CURL *curl[NUM_HANDLES] = {0};
  35. int running;
  36. CURLM *m = NULL;
  37. int i;
  38. char target_url[256];
  39. char dnsentry[256];
  40. struct curl_slist *slist = NULL;
  41. char *port = libtest_arg3;
  42. char *address = libtest_arg2;
  43. (void)URL;
  44. msnprintf(dnsentry, sizeof(dnsentry), "localhost:%s:%s",
  45. port, address);
  46. printf("%s\n", dnsentry);
  47. slist = curl_slist_append(slist, dnsentry);
  48. if(!slist) {
  49. fprintf(stderr, "curl_slist_append() failed\n");
  50. goto test_cleanup;
  51. }
  52. start_test_timing();
  53. global_init(CURL_GLOBAL_ALL);
  54. multi_init(m);
  55. multi_setopt(m, CURLMOPT_MAXCONNECTS, 1L);
  56. /* get NUM_HANDLES easy handles */
  57. for(i = 0; i < NUM_HANDLES; i++) {
  58. /* get an easy handle */
  59. easy_init(curl[i]);
  60. /* specify target */
  61. msnprintf(target_url, sizeof(target_url),
  62. "https://localhost:%s/path/2502%04i",
  63. port, i + 1);
  64. target_url[sizeof(target_url) - 1] = '\0';
  65. easy_setopt(curl[i], CURLOPT_URL, target_url);
  66. /* go http2 */
  67. easy_setopt(curl[i], CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_3ONLY);
  68. easy_setopt(curl[i], CURLOPT_CONNECTTIMEOUT_MS, (long)5000);
  69. easy_setopt(curl[i], CURLOPT_CAINFO, "./certs/EdelCurlRoot-ca.cacert");
  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. libtest_debug_config.nohex = 1;
  74. libtest_debug_config.tracetime = 0;
  75. test_setopt(curl[i], CURLOPT_DEBUGDATA, &libtest_debug_config);
  76. easy_setopt(curl[i], CURLOPT_DEBUGFUNCTION, libtest_debug_cb);
  77. easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
  78. /* include headers */
  79. easy_setopt(curl[i], CURLOPT_HEADER, 1L);
  80. easy_setopt(curl[i], CURLOPT_RESOLVE, slist);
  81. }
  82. fprintf(stderr, "Start at URL 0\n");
  83. for(i = 0; i < NUM_HANDLES; i++) {
  84. /* add handle to multi */
  85. multi_add_handle(m, curl[i]);
  86. for(;;) {
  87. struct timeval interval;
  88. fd_set rd, wr, exc;
  89. int maxfd = -99;
  90. interval.tv_sec = 1;
  91. interval.tv_usec = 0;
  92. multi_perform(m, &running);
  93. abort_on_test_timeout();
  94. if(!running)
  95. break; /* done */
  96. FD_ZERO(&rd);
  97. FD_ZERO(&wr);
  98. FD_ZERO(&exc);
  99. multi_fdset(m, &rd, &wr, &exc, &maxfd);
  100. /* At this point, maxfd is guaranteed to be greater or equal than -1. */
  101. select_test(maxfd + 1, &rd, &wr, &exc, &interval);
  102. abort_on_test_timeout();
  103. }
  104. wait_ms(1); /* to ensure different end times */
  105. }
  106. test_cleanup:
  107. /* proper cleanup sequence - type PB */
  108. for(i = 0; i < NUM_HANDLES; i++) {
  109. curl_multi_remove_handle(m, curl[i]);
  110. curl_easy_cleanup(curl[i]);
  111. }
  112. curl_slist_free_all(slist);
  113. curl_multi_cleanup(m);
  114. curl_global_cleanup();
  115. return res;
  116. }