lib504.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  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. /*
  30. * Source code in here hugely as reported in bug report 651464 by
  31. * Christopher R. Palmer.
  32. *
  33. * Use multi interface to get document over proxy with bad port number.
  34. * This caused the interface to "hang" in libcurl 7.10.2.
  35. */
  36. int test(char *URL)
  37. {
  38. CURL *c = NULL;
  39. int res = 0;
  40. CURLM *m = NULL;
  41. fd_set rd, wr, exc;
  42. int running;
  43. start_test_timing();
  44. global_init(CURL_GLOBAL_ALL);
  45. easy_init(c);
  46. /* The point here is that there must not be anything running on the given
  47. proxy port */
  48. if(libtest_arg2)
  49. easy_setopt(c, CURLOPT_PROXY, libtest_arg2);
  50. easy_setopt(c, CURLOPT_URL, URL);
  51. easy_setopt(c, CURLOPT_VERBOSE, 1L);
  52. multi_init(m);
  53. multi_add_handle(m, c);
  54. for(;;) {
  55. struct timeval interval;
  56. int maxfd = -99;
  57. interval.tv_sec = 1;
  58. interval.tv_usec = 0;
  59. fprintf(stderr, "curl_multi_perform()\n");
  60. multi_perform(m, &running);
  61. abort_on_test_timeout();
  62. if(!running) {
  63. /* This is where this code is expected to reach */
  64. int numleft;
  65. CURLMsg *msg = curl_multi_info_read(m, &numleft);
  66. fprintf(stderr, "Expected: not running\n");
  67. if(msg && !numleft)
  68. res = TEST_ERR_SUCCESS; /* this is where we should be */
  69. else
  70. res = TEST_ERR_FAILURE; /* not correct */
  71. break; /* done */
  72. }
  73. fprintf(stderr, "running == %d\n", running);
  74. FD_ZERO(&rd);
  75. FD_ZERO(&wr);
  76. FD_ZERO(&exc);
  77. fprintf(stderr, "curl_multi_fdset()\n");
  78. multi_fdset(m, &rd, &wr, &exc, &maxfd);
  79. /* At this point, maxfd is guaranteed to be greater or equal than -1. */
  80. select_test(maxfd + 1, &rd, &wr, &exc, &interval);
  81. abort_on_test_timeout();
  82. }
  83. test_cleanup:
  84. /* proper cleanup sequence - type PA */
  85. curl_multi_remove_handle(m, c);
  86. curl_multi_cleanup(m);
  87. curl_easy_cleanup(c);
  88. curl_global_cleanup();
  89. return res;
  90. }