lib1510.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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_URLS 4
  30. int test(char *URL)
  31. {
  32. int res = 0;
  33. CURL *curl = 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_URLS; i++) {
  43. msnprintf(dnsentry, sizeof(dnsentry), "server%d.example.com:%s:%s", i + 1,
  44. 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. /* get an easy handle */
  56. easy_init(curl);
  57. /* go verbose */
  58. easy_setopt(curl, CURLOPT_VERBOSE, 1L);
  59. /* include headers */
  60. easy_setopt(curl, CURLOPT_HEADER, 1L);
  61. easy_setopt(curl, CURLOPT_RESOLVE, slist);
  62. easy_setopt(curl, CURLOPT_MAXCONNECTS, 3L);
  63. /* get NUM_HANDLES easy handles */
  64. for(i = 0; i < NUM_URLS; i++) {
  65. /* specify target */
  66. msnprintf(target_url, sizeof(target_url),
  67. "http://server%d.example.com:%s/path/1510%04i",
  68. i + 1, port, i + 1);
  69. target_url[sizeof(target_url) - 1] = '\0';
  70. easy_setopt(curl, CURLOPT_URL, target_url);
  71. res = curl_easy_perform(curl);
  72. abort_on_test_timeout();
  73. }
  74. test_cleanup:
  75. /* proper cleanup sequence - type PB */
  76. curl_easy_cleanup(curl);
  77. curl_slist_free_all(slist);
  78. curl_global_cleanup();
  79. return res;
  80. }