Skip to content
Snippets Groups Projects
Verified Commit 5393e25d authored by Nicolas Werner's avatar Nicolas Werner
Browse files

Limit connections by default

parent 87517c54
No related branches found
No related tags found
No related merge requests found
default: true,
CHANGELOG
=========
## [0.2.0] - 2022-03-06
[0.2.1] - unreleased
--------------------
- Fix potential hang when the client is shutdown and a request is scheduled at the same time.
- Limit concurrent connections to 64 and per host to 8 by default. You can
change that using 2 new functions.
## [0.1.1] - 2021-12-20
[0.2.0] - 2022-03-06
--------------------
- Fix potential hang when the client is shutdown and a request is scheduled at
the same time.
[0.1.1] - 2021-12-20
--------------------
- Add wrapper function to convert error codes to strings.
## [0.1.0] - 2021-11-14
[0.1.0] - 2021-11-14
--------------------
- Initial release.
......@@ -145,6 +145,12 @@ struct Client {
//! stops sending acks.
void connection_timeout(long t) { connection_timeout_ = t; }
//! Maximum connections to open in parallel for this client. Set to 0 to disable the limit. Default is 64.
void maximum_total_connections(long count);
//! Maximum connections to open in parallel for each specific host for this client. Set to 0 to disable the limit.
//! Default is 8.
void maximum_connections_per_host(long count);
private:
// Call this to run the event loop. Will block until the client is shutdown.
void run();
......
......@@ -232,9 +232,20 @@ Client::Client() {
curl_multi_setopt(this->multi, CURLMOPT_TIMERFUNCTION, multi_timer_cb);
curl_multi_setopt(this->multi, CURLMOPT_TIMERDATA, this);
maximum_total_connections(64);
maximum_connections_per_host(8);
bg_thread = std::thread([this]() { this->run(); });
}
void Client::maximum_total_connections(long count) {
curl_multi_setopt(this->multi, CURLMOPT_MAX_TOTAL_CONNECTIONS, count);
}
void Client::maximum_connections_per_host(long count) {
curl_multi_setopt(this->multi, CURLMOPT_MAX_HOST_CONNECTIONS, count);
}
Client::~Client() {
close();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment