lib1510.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 2013 - 2020, 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. ***************************************************************************/
  22. #include "test.h"
  23. #include "testutil.h"
  24. #include "warnless.h"
  25. #include "memdebug.h"
  26. #define TEST_HANG_TIMEOUT 60 * 1000
  27. #define NUM_URLS 4
  28. int test(char *URL)
  29. {
  30. int res = 0;
  31. CURL *curl = NULL;
  32. int i;
  33. char target_url[256];
  34. char dnsentry[256];
  35. struct curl_slist *slist = NULL, *slist2;
  36. char *port = libtest_arg3;
  37. char *address = libtest_arg2;
  38. (void)URL;
  39. /* Create fake DNS entries for serverX.example.com for all handles */
  40. for(i = 0; i < NUM_URLS; i++) {
  41. msnprintf(dnsentry, sizeof(dnsentry), "server%d.example.com:%s:%s", i + 1,
  42. port, address);
  43. printf("%s\n", dnsentry);
  44. slist2 = curl_slist_append(slist, dnsentry);
  45. if(!slist2) {
  46. fprintf(stderr, "curl_slist_append() failed\n");
  47. goto test_cleanup;
  48. }
  49. slist = slist2;
  50. }
  51. start_test_timing();
  52. global_init(CURL_GLOBAL_ALL);
  53. /* get an easy handle */
  54. easy_init(curl);
  55. /* go verbose */
  56. easy_setopt(curl, CURLOPT_VERBOSE, 1L);
  57. /* include headers */
  58. easy_setopt(curl, CURLOPT_HEADER, 1L);
  59. easy_setopt(curl, CURLOPT_RESOLVE, slist);
  60. easy_setopt(curl, CURLOPT_MAXCONNECTS, 3L);
  61. /* get NUM_HANDLES easy handles */
  62. for(i = 0; i < NUM_URLS; i++) {
  63. /* specify target */
  64. msnprintf(target_url, sizeof(target_url),
  65. "http://server%d.example.com:%s/path/1510%04i",
  66. i + 1, port, i + 1);
  67. target_url[sizeof(target_url) - 1] = '\0';
  68. easy_setopt(curl, CURLOPT_URL, target_url);
  69. res = curl_easy_perform(curl);
  70. abort_on_test_timeout();
  71. }
  72. test_cleanup:
  73. /* proper cleanup sequence - type PB */
  74. curl_easy_cleanup(curl);
  75. curl_slist_free_all(slist);
  76. curl_global_cleanup();
  77. return res;
  78. }