lib504.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. CURLcode test(char *URL)
  37. {
  38. CURL *c = NULL;
  39. CURLcode res = CURLE_OK;
  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. while(running) {
  62. CURLMcode mres;
  63. int num;
  64. mres = curl_multi_wait(m, NULL, 0, TEST_HANG_TIMEOUT, &num);
  65. if(mres != CURLM_OK) {
  66. printf("curl_multi_wait() returned %d\n", mres);
  67. res = TEST_ERR_MAJOR_BAD;
  68. goto test_cleanup;
  69. }
  70. abort_on_test_timeout();
  71. multi_perform(m, &running);
  72. abort_on_test_timeout();
  73. }
  74. abort_on_test_timeout();
  75. if(!running) {
  76. /* This is where this code is expected to reach */
  77. int numleft;
  78. CURLMsg *msg = curl_multi_info_read(m, &numleft);
  79. fprintf(stderr, "Expected: not running\n");
  80. if(msg && !numleft)
  81. res = TEST_ERR_SUCCESS; /* this is where we should be */
  82. else
  83. res = TEST_ERR_FAILURE; /* not correct */
  84. break; /* done */
  85. }
  86. fprintf(stderr, "running == %d\n", running);
  87. FD_ZERO(&rd);
  88. FD_ZERO(&wr);
  89. FD_ZERO(&exc);
  90. fprintf(stderr, "curl_multi_fdset()\n");
  91. multi_fdset(m, &rd, &wr, &exc, &maxfd);
  92. /* At this point, maxfd is guaranteed to be greater or equal than -1. */
  93. select_test(maxfd + 1, &rd, &wr, &exc, &interval);
  94. abort_on_test_timeout();
  95. }
  96. test_cleanup:
  97. /* proper cleanup sequence - type PA */
  98. curl_multi_remove_handle(m, c);
  99. curl_multi_cleanup(m);
  100. curl_easy_cleanup(c);
  101. curl_global_cleanup();
  102. return res;
  103. }