lib504.c 2.9 KB

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