lib504.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "test.h"
  2. #include <sys/time.h>
  3. #include <sys/types.h>
  4. /*
  5. * Source code in here hugely as reported in bug report 651464 by
  6. * Christopher R. Palmer.
  7. *
  8. * Use multi interface to get document over proxy with bad port number.
  9. * This caused the interface to "hang" in libcurl 7.10.2.
  10. */
  11. int test(char *URL)
  12. {
  13. CURL *c;
  14. int ret=0;
  15. CURLM *m;
  16. fd_set rd, wr, exc;
  17. CURLMcode res;
  18. int running;
  19. int max_fd;
  20. int rc;
  21. curl_global_init(CURL_GLOBAL_ALL);
  22. c = curl_easy_init();
  23. /* the point here being that there must not run anything on the given
  24. proxy port */
  25. curl_easy_setopt(c, CURLOPT_PROXY, arg2);
  26. curl_easy_setopt(c, CURLOPT_URL, URL);
  27. curl_easy_setopt(c, CURLOPT_VERBOSE, 1);
  28. m = curl_multi_init();
  29. res = curl_multi_add_handle(m, c);
  30. if(res && (res != CURLM_CALL_MULTI_PERFORM))
  31. return 1; /* major failure */
  32. do {
  33. struct timeval interval;
  34. interval.tv_sec = 1;
  35. interval.tv_usec = 0;
  36. fprintf(stderr, "curl_multi_perform()\n");
  37. do {
  38. res = curl_multi_perform(m, &running);
  39. } while (res == CURLM_CALL_MULTI_PERFORM);
  40. if(!running) {
  41. /* This is where this code is expected to reach */
  42. int numleft;
  43. CURLMsg *msg = curl_multi_info_read(m, &numleft);
  44. fprintf(stderr, "Expected: not running\n");
  45. if(msg && !numleft)
  46. ret = 100; /* this is where we should be */
  47. else
  48. ret = 99; /* not correct */
  49. break;
  50. }
  51. fprintf(stderr, "running == %d, res == %d\n", running, res);
  52. if (res != CURLM_OK) {
  53. ret = 2;
  54. break;
  55. }
  56. FD_ZERO(&rd);
  57. FD_ZERO(&wr);
  58. FD_ZERO(&exc);
  59. max_fd = 0;
  60. fprintf(stderr, "curl_multi_fdset()\n");
  61. if (curl_multi_fdset(m, &rd, &wr, &exc, &max_fd) != CURLM_OK) {
  62. fprintf(stderr, "unexpected failured of fdset.\n");
  63. ret = 3;
  64. break;
  65. }
  66. rc = select(max_fd+1, &rd, &wr, &exc, &interval);
  67. fprintf(stderr, "select returned %d\n", rc);
  68. } while(rc);
  69. curl_multi_remove_handle(m, c);
  70. curl_easy_cleanup(c);
  71. curl_multi_cleanup(m);
  72. return ret;
  73. }