1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2017, 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 https://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_MS 500
39 CURLM *mhandle = NULL;
41 int still_running = 0;
45 global_init(CURL_GLOBAL_ALL);
49 easy_setopt(handle, CURLOPT_URL, URL);
50 easy_setopt(handle, CURLOPT_VERBOSE, 1L);
54 multi_add_handle(mhandle, handle);
56 multi_perform(mhandle, &still_running);
58 abort_on_test_timeout();
60 while(still_running) {
61 struct timeval timeout;
66 struct timeval before;
71 timeout.tv_usec = 100000L; /* 100 ms */
77 multi_fdset(mhandle, &fdread, &fdwrite, &fdexcep, &maxfd);
79 /* At this point, maxfd is guaranteed to be greater or equal than -1. */
81 select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
83 abort_on_test_timeout();
85 fprintf(stderr, "ping\n");
86 before = tutil_tvnow();
88 multi_perform(mhandle, &still_running);
90 abort_on_test_timeout();
92 after = tutil_tvnow();
93 e = tutil_tvdiff(after, before);
94 fprintf(stderr, "pong = %ld\n", e);
96 if(e > MAX_BLOCKED_TIME_MS) {
104 /* undocumented cleanup sequence - type UA */
106 curl_multi_cleanup(mhandle);
107 curl_easy_cleanup(handle);
108 curl_global_cleanup();