1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
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 http://curl.haxx.se/docs/copyright.html.
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.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
30 #define TEST_HANG_TIMEOUT 30 * 1000
32 /* 500 milliseconds allowed. An extreme number but lets be really conservative
33 to allow old and slow machines to run this test too */
34 #define MAX_BLOCKED_TIME_US 500000
36 /* return the number of microseconds between two time stamps */
37 static int elapsed(struct timeval *before,
38 struct timeval *after)
42 result = (after->tv_sec - before->tv_sec) * 1000000 +
43 after->tv_usec - before->tv_usec;
47 return curlx_sztosi(result);
54 CURLM *mhandle = NULL;
56 int still_running = 0;
60 global_init(CURL_GLOBAL_ALL);
64 easy_setopt(handle, CURLOPT_URL, URL);
65 easy_setopt(handle, CURLOPT_VERBOSE, 1L);
69 multi_add_handle(mhandle, handle);
71 multi_perform(mhandle, &still_running);
73 abort_on_test_timeout();
75 while(still_running) {
76 struct timeval timeout;
81 struct timeval before;
86 timeout.tv_usec = 100000L; /* 100 ms */
92 multi_fdset(mhandle, &fdread, &fdwrite, &fdexcep, &maxfd);
94 /* At this point, maxfd is guaranteed to be greater or equal than -1. */
96 select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
98 abort_on_test_timeout();
100 fprintf(stderr, "ping\n");
101 before = tutil_tvnow();
103 multi_perform(mhandle, &still_running);
105 abort_on_test_timeout();
107 after = tutil_tvnow();
108 e = elapsed(&before, &after);
109 fprintf(stderr, "pong = %d\n", e);
111 if(e > MAX_BLOCKED_TIME_US) {
119 /* undocumented cleanup sequence - type UA */
121 curl_multi_cleanup(mhandle);
122 curl_easy_cleanup(handle);
123 curl_global_cleanup();