/***************************************************************************1* _ _ ____ _2* Project ___| | | | _ \| |3* / __| | | | |_) | |4* | (__| |_| | _ <| |___5* \___|\___/|_| \_\_____|6*7* Copyright (C) Daniel Stenberg, <[email protected]>, et al.8*9* This software is licensed as described in the file COPYING, which10* you should have received as part of this distribution. The terms11* are also available at https://curl.se/docs/copyright.html.12*13* You may opt to use, copy, modify, merge, publish, distribute and/or sell14* copies of the Software, and permit persons to whom the Software is15* furnished to do so, under the terms of the COPYING file.16*17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY18* KIND, either express or implied.19*20* SPDX-License-Identifier: curl21*22***************************************************************************/23#include "test.h"2425#include <fcntl.h>2627#include "testutil.h"28#include "warnless.h"29#include "memdebug.h"3031#define TEST_HANG_TIMEOUT 30 * 10003233/* 500 milliseconds allowed. An extreme number but lets be really conservative34to allow old and slow machines to run this test too */35#define MAX_BLOCKED_TIME_MS 5003637CURLcode test(char *URL)38{39CURL *handle = NULL;40CURLM *mhandle = NULL;41CURLcode res = CURLE_OK;42int still_running = 0;4344start_test_timing();4546global_init(CURL_GLOBAL_ALL);4748easy_init(handle);4950easy_setopt(handle, CURLOPT_URL, URL);51easy_setopt(handle, CURLOPT_VERBOSE, 1L);5253multi_init(mhandle);5455multi_add_handle(mhandle, handle);5657multi_perform(mhandle, &still_running);5859abort_on_test_timeout();6061while(still_running) {62struct timeval timeout;63fd_set fdread;64fd_set fdwrite;65fd_set fdexcep;66int maxfd = -99;67struct timeval before;68struct timeval after;69long e;7071timeout.tv_sec = 0;72timeout.tv_usec = 100000L; /* 100 ms */7374FD_ZERO(&fdread);75FD_ZERO(&fdwrite);76FD_ZERO(&fdexcep);7778multi_fdset(mhandle, &fdread, &fdwrite, &fdexcep, &maxfd);7980/* At this point, maxfd is guaranteed to be greater or equal than -1. */8182select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);8384abort_on_test_timeout();8586curl_mfprintf(stderr, "ping\n");87before = tutil_tvnow();8889multi_perform(mhandle, &still_running);9091abort_on_test_timeout();9293after = tutil_tvnow();94e = tutil_tvdiff(after, before);95curl_mfprintf(stderr, "pong = %ld\n", e);9697if(e > MAX_BLOCKED_TIME_MS) {98res = CURLE_TOO_LARGE;99break;100}101}102103test_cleanup:104105/* undocumented cleanup sequence - type UA */106107curl_multi_cleanup(mhandle);108curl_easy_cleanup(handle);109curl_global_cleanup();110111return res;112}113114115