2
0

lib2502.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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/2502%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_3ONLY);
  67. easy_setopt(curl[i], CURLOPT_CONNECTTIMEOUT_MS, (long)5000);
  68. easy_setopt(curl[i], CURLOPT_CAINFO, "./certs/EdelCurlRoot-ca.cacert");
  69. /* wait for first connection established to see if we can share it */
  70. easy_setopt(curl[i], CURLOPT_PIPEWAIT, 1L);
  71. /* go verbose */
  72. easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
  73. /* include headers */
  74. easy_setopt(curl[i], CURLOPT_HEADER, 1L);
  75. easy_setopt(curl[i], CURLOPT_RESOLVE, slist);
  76. }
  77. fprintf(stderr, "Start at URL 0\n");
  78. for(i = 0; i < NUM_HANDLES; i++) {
  79. /* add handle to multi */
  80. multi_add_handle(m, curl[i]);
  81. for(;;) {
  82. struct timeval interval;
  83. fd_set rd, wr, exc;
  84. int maxfd = -99;
  85. interval.tv_sec = 1;
  86. interval.tv_usec = 0;
  87. multi_perform(m, &running);
  88. abort_on_test_timeout();
  89. if(!running)
  90. break; /* done */
  91. FD_ZERO(&rd);
  92. FD_ZERO(&wr);
  93. FD_ZERO(&exc);
  94. multi_fdset(m, &rd, &wr, &exc, &maxfd);
  95. /* At this point, maxfd is guaranteed to be greater or equal than -1. */
  96. select_test(maxfd + 1, &rd, &wr, &exc, &interval);
  97. abort_on_test_timeout();
  98. }
  99. wait_ms(1); /* to ensure different end times */
  100. }
  101. test_cleanup:
  102. /* proper cleanup sequence - type PB */
  103. for(i = 0; i < NUM_HANDLES; i++) {
  104. curl_multi_remove_handle(m, curl[i]);
  105. curl_easy_cleanup(curl[i]);
  106. }
  107. curl_slist_free_all(slist);
  108. curl_multi_cleanup(m);
  109. curl_global_cleanup();
  110. return res;
  111. }