Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bindings for CURLMOPT_MAXCONNECTS and CURLMOPT_MAX_TOTAL_CONNECTIONS #301

Merged
merged 1 commit into from
Sep 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions curl-sys/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -899,14 +899,14 @@ pub const CURLMOPT_SOCKETDATA: CURLMoption = CURLOPTTYPE_OBJECTPOINT + 2;
pub const CURLMOPT_PIPELINING: CURLMoption = CURLOPTTYPE_LONG + 3;
pub const CURLMOPT_TIMERFUNCTION: CURLMoption = CURLOPTTYPE_FUNCTIONPOINT + 4;
pub const CURLMOPT_TIMERDATA: CURLMoption = CURLOPTTYPE_OBJECTPOINT + 5;
// pub const CURLMOPT_MAXCONNECTS: CURLMoption = CURLOPTTYPE_LONG + 6;
pub const CURLMOPT_MAXCONNECTS: CURLMoption = CURLOPTTYPE_LONG + 6;
pub const CURLMOPT_MAX_HOST_CONNECTIONS: CURLMoption = CURLOPTTYPE_LONG + 7;
pub const CURLMOPT_MAX_PIPELINE_LENGTH: CURLMoption = CURLOPTTYPE_LONG + 8;
// pub const CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE: CURLMoption = CURLOPTTYPE_OFF_T + 9;
// pub const CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE: CURLMoption = CURLOPTTYPE_OFF_T + 10;
// pub const CURLMOPT_PIPELINING_SITE_BL: CURLMoption = CURLOPTTYPE_OBJECTPOINT + 11;
// pub const CURLMOPT_PIPELINING_SERVER_BL: CURLMoption = CURLOPTTYPE_OBJECTPOINT + 12;
// pub const CURLMOPT_MAX_TOTAL_CONNECTIONS: CURLMoption = CURLOPTTYPE_LONG + 13;
pub const CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE: CURLMoption = CURLOPTTYPE_OFF_T + 9;
pub const CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE: CURLMoption = CURLOPTTYPE_OFF_T + 10;
pub const CURLMOPT_PIPELINING_SITE_BL: CURLMoption = CURLOPTTYPE_OBJECTPOINT + 11;
pub const CURLMOPT_PIPELINING_SERVER_BL: CURLMoption = CURLOPTTYPE_OBJECTPOINT + 12;
pub const CURLMOPT_MAX_TOTAL_CONNECTIONS: CURLMoption = CURLOPTTYPE_LONG + 13;

// These enums are for use with the CURLMOPT_PIPELINING option.
pub const CURLPIPE_NOTHING: c_long = 0;
Expand Down
36 changes: 36 additions & 0 deletions src/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,37 @@ impl Multi {
self.setopt_long(curl_sys::CURLMOPT_MAX_HOST_CONNECTIONS, val as c_long)
}

/// Sets the max simultaneously open connections.
///
/// The set number will be used as the maximum number of simultaneously open
/// connections in total using this multi handle. For each new session,
/// libcurl will open a new connection up to the limit set by the provided
/// value. When the limit is reached, the sessions will be pending until
/// there are available connections. If pipelining is enabled, libcurl will
/// try to pipeline or use multiplexing if the host is capable of it.
pub fn set_max_total_connections(&mut self, val: usize) -> Result<(), MultiError> {
self.setopt_long(curl_sys::CURLMOPT_MAX_TOTAL_CONNECTIONS, val as c_long)
}

/// Set size of connection cache.
///
/// The set number will be used as the maximum amount of simultaneously open
/// connections that libcurl may keep in its connection cache after
/// completed use. By default libcurl will enlarge the size for each added
/// easy handle to make it fit 4 times the number of added easy handles.
///
/// By setting this option, you can prevent the cache size from growing
/// beyond the limit set by you.
///
/// When the cache is full, curl closes the oldest one in the cache to
/// prevent the number of open connections from increasing.
///
/// See [`set_max_total_connections`](#method.set_max_total_connections) for
/// limiting the number of active connections.
pub fn set_max_connects(&mut self, val: usize) -> Result<(), MultiError> {
self.setopt_long(curl_sys::CURLMOPT_MAXCONNECTS, val as c_long)
}

/// Sets the pipeline length.
///
/// This sets the max number that will be used as the maximum amount of
Expand Down Expand Up @@ -673,6 +704,11 @@ impl Multi {
pub fn close(&self) -> Result<(), MultiError> {
unsafe { cvt(curl_sys::curl_multi_cleanup(self.raw)) }
}

/// Get a pointer to the raw underlying CURLM handle.
pub fn raw(&self) -> *mut curl_sys::CURLM {
self.raw
}
}

fn cvt(code: curl_sys::CURLMcode) -> Result<(), MultiError> {
Expand Down