example/maxconnects: set maxconnects example#11343
Closed
Conversation
Member
|
Since maxconnects limits the number of connections kept alive, maybe this example should just loop over 2 or three different URLs so that a user could see (in the verbose output) that it will close connections that otherwise would have been kept alive? |
Member
|
Here's my proposed extended version: /***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) James Fuller, <jim@webcomposite.com>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
/* <DESC>
* Set maximum number of persistent connections to 1.
* </DESC>
*/
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
const char *urls[] = { "https://example.com",
"https://curl.se",
"https://www.example/",
NULL /* end of list */
};
int i = 0;
/* Change the maximum number of persistent connection */
curl_easy_setopt(curl, CURLOPT_MAXCONNECTS, 1L);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
/* loop over the URLs */
while(urls[i]) {
curl_easy_setopt(curl, CURLOPT_URL, urls[i]);
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
i++;
}
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
} |
bch
pushed a commit
to bch/curl
that referenced
this pull request
Jul 19, 2023
ptitSeb
pushed a commit
to wasix-org/curl
that referenced
this pull request
Sep 25, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.