/***************************************************************************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 "first.h"2425#include "memdebug.h"2627static CURLcode test_lib1501(const char *URL)28{29static const long HANG_TIMEOUT = 30 * 1000;30/* 500 milliseconds allowed. An extreme number but lets be really31conservative to allow old and slow machines to run this test too */32static const int MAX_BLOCKED_TIME_MS = 500;3334CURL *curl = NULL;35CURLM *multi = NULL;36CURLcode res = CURLE_OK;37int still_running = 0;3839start_test_timing();4041global_init(CURL_GLOBAL_ALL);4243easy_init(curl);4445easy_setopt(curl, CURLOPT_URL, URL);46easy_setopt(curl, CURLOPT_VERBOSE, 1L);4748multi_init(multi);4950multi_add_handle(multi, curl);5152multi_perform(multi, &still_running);5354abort_on_test_timeout_custom(HANG_TIMEOUT);5556while(still_running) {57struct timeval timeout;58fd_set fdread;59fd_set fdwrite;60fd_set fdexcep;61int maxfd = -99;62struct curltime before;63struct curltime after;64timediff_t e;6566timeout.tv_sec = 0;67timeout.tv_usec = 100000L; /* 100 ms */6869FD_ZERO(&fdread);70FD_ZERO(&fdwrite);71FD_ZERO(&fdexcep);7273multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);7475/* At this point, maxfd is guaranteed to be greater or equal than -1. */7677select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);7879abort_on_test_timeout_custom(HANG_TIMEOUT);8081curl_mfprintf(stderr, "ping\n");82before = curlx_now();8384multi_perform(multi, &still_running);8586abort_on_test_timeout_custom(HANG_TIMEOUT);8788after = curlx_now();89e = curlx_timediff(after, before);90curl_mfprintf(stderr, "pong = %ld\n", (long)e);9192if(e > MAX_BLOCKED_TIME_MS) {93res = CURLE_TOO_LARGE;94break;95}96}9798test_cleanup:99100/* undocumented cleanup sequence - type UA */101102curl_multi_cleanup(multi);103curl_easy_cleanup(curl);104curl_global_cleanup();105106return res;107}108109110