Path: blob/main/external/curl/tests/libtest/cli_h2_upgrade_extreme.c
2659 views
/***************************************************************************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 "testtrace.h"26#include "memdebug.h"2728static size_t write_h2_upg_extreme_cb(char *ptr, size_t size, size_t nmemb,29void *opaque)30{31(void)ptr;32(void)opaque;33return size * nmemb;34}3536static CURLcode test_cli_h2_upgrade_extreme(const char *URL)37{38CURLM *multi = NULL;39CURL *curl;40CURLMcode mc;41int running_handles = 0, start_count, numfds;42CURLMsg *msg;43int msgs_in_queue;44char range[128];45CURLcode result = (CURLcode)1;4647if(!URL) {48curl_mfprintf(stderr, "need URL as argument\n");49return (CURLcode)2;50}5152if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {53curl_mfprintf(stderr, "curl_global_init() failed\n");54return (CURLcode)3;55}5657multi = curl_multi_init();58if(!multi) {59curl_mfprintf(stderr, "curl_multi_init failed\n");60goto cleanup;61}6263start_count = 200;64do {65if(start_count) {66curl = curl_easy_init();67if(!curl) {68curl_mfprintf(stderr, "curl_easy_init failed\n");69goto cleanup;70}71curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);72curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, cli_debug_cb);73curl_easy_setopt(curl, CURLOPT_URL, URL);74curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);75curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 1L);76curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);77curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);78curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_h2_upg_extreme_cb);79curl_easy_setopt(curl, CURLOPT_WRITEDATA, NULL);80curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);81curl_msnprintf(range, sizeof(range),82"%" CURL_FORMAT_CURL_OFF_TU "-"83"%" CURL_FORMAT_CURL_OFF_TU,84(curl_off_t)0,85(curl_off_t)16384);86curl_easy_setopt(curl, CURLOPT_RANGE, range);8788mc = curl_multi_add_handle(multi, curl);89if(mc != CURLM_OK) {90curl_mfprintf(stderr, "curl_multi_add_handle: %s\n",91curl_multi_strerror(mc));92curl_easy_cleanup(curl);93goto cleanup;94}95--start_count;96}9798mc = curl_multi_perform(multi, &running_handles);99if(mc != CURLM_OK) {100curl_mfprintf(stderr, "curl_multi_perform: %s\n",101curl_multi_strerror(mc));102goto cleanup;103}104105if(running_handles) {106mc = curl_multi_poll(multi, NULL, 0, 1000000, &numfds);107if(mc != CURLM_OK) {108curl_mfprintf(stderr, "curl_multi_poll: %s\n",109curl_multi_strerror(mc));110goto cleanup;111}112}113114/* Check for finished handles and remove. */115/* !checksrc! disable EQUALSNULL 1 */116while((msg = curl_multi_info_read(multi, &msgs_in_queue)) != NULL) {117if(msg->msg == CURLMSG_DONE) {118long status = 0;119curl_off_t xfer_id;120curl_easy_getinfo(msg->easy_handle, CURLINFO_XFER_ID, &xfer_id);121curl_easy_getinfo(msg->easy_handle, CURLINFO_RESPONSE_CODE, &status);122if(msg->data.result == CURLE_SEND_ERROR ||123msg->data.result == CURLE_RECV_ERROR) {124/* We get these if the server had a GOAWAY in transit on125* reusing a connection */126}127else if(msg->data.result) {128curl_mfprintf(stderr, "transfer #%" CURL_FORMAT_CURL_OFF_T129": failed with %d\n", xfer_id, msg->data.result);130goto cleanup;131}132else if(status != 206) {133curl_mfprintf(stderr, "transfer #%" CURL_FORMAT_CURL_OFF_T134": wrong http status %ld (expected 206)\n", xfer_id,135status);136goto cleanup;137}138curl_multi_remove_handle(multi, msg->easy_handle);139curl_easy_cleanup(msg->easy_handle);140curl_mfprintf(stderr, "transfer #%" CURL_FORMAT_CURL_OFF_T" retiring "141"(%d now running)\n", xfer_id, running_handles);142}143}144145curl_mfprintf(stderr, "running_handles=%d, yet_to_start=%d\n",146running_handles, start_count);147148} while(running_handles > 0 || start_count);149150curl_mfprintf(stderr, "exiting\n");151result = CURLE_OK;152153cleanup:154155if(multi) {156CURL **list = curl_multi_get_handles(multi);157if(list) {158int i;159for(i = 0; list[i]; i++) {160curl_multi_remove_handle(multi, list[i]);161curl_easy_cleanup(list[i]);162}163curl_free(list);164}165curl_multi_cleanup(multi);166}167168curl_global_cleanup();169170return result;171}172173174