Skip to content

Commit

Permalink
Add Max Age CURL Option (#360)
Browse files Browse the repository at this point in the history
* add max age option to CURL system crate

* correctly identify constant and expose Rust API

* correct API
  • Loading branch information
gsquire authored Oct 11, 2020
1 parent badb448 commit 454a720
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions curl-sys/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,8 @@ pub const CURLOPT_PROXY_CAPATH: CURLoption = CURLOPTTYPE_OBJECTPOINT + 247;
pub const CURLOPT_PROXY_SSLCERT: CURLoption = CURLOPTTYPE_OBJECTPOINT + 254;
pub const CURLOPT_PROXY_SSLKEY: CURLoption = CURLOPTTYPE_OBJECTPOINT + 256;

pub const CURLOPT_MAXAGE_CONN: CURLoption = CURLOPTTYPE_LONG + 288;

pub const CURL_IPRESOLVE_WHATEVER: c_int = 0;
pub const CURL_IPRESOLVE_V4: c_int = 1;
pub const CURL_IPRESOLVE_V6: c_int = 2;
Expand Down
5 changes: 5 additions & 0 deletions src/easy/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,11 @@ impl Easy {
self.inner.max_connects(max)
}

/// Same as [`Easy2::maxage_conn`](struct.Easy2.html#method.maxage_conn)
pub fn maxage_conn(&mut self, max_age: Duration) -> Result<(), Error> {
self.inner.maxage_conn(max_age)
}

/// Same as [`Easy2::fresh_connect`](struct.Easy2.html#method.fresh_connect)
pub fn fresh_connect(&mut self, enable: bool) -> Result<(), Error> {
self.inner.fresh_connect(enable)
Expand Down
11 changes: 11 additions & 0 deletions src/easy/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,17 @@ impl<H> Easy2<H> {
self.setopt_long(curl_sys::CURLOPT_MAXCONNECTS, max as c_long)
}

/// Set the maximum idle time allowed for a connection.
///
/// This configuration sets the maximum time that a connection inside of the connection cache
/// can be reused. Any connection older than this value will be considered stale and will
/// be closed.
///
/// By default, a value of 118 seconds is used.
pub fn maxage_conn(&mut self, max_age: Duration) -> Result<(), Error> {
self.setopt_long(curl_sys::CURLOPT_MAXAGE_CONN, max_age.as_secs() as c_long)
}

/// Force a new connection to be used.
///
/// Makes the next transfer use a new (fresh) connection by force instead of
Expand Down
1 change: 1 addition & 0 deletions systest/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ fn main() {
if version < 66 {
match s {
"CURL_HTTP_VERSION_3" => return true,
"CURLOPT_MAXAGE_CONN" => return true,
_ => {}
}
}
Expand Down

0 comments on commit 454a720

Please sign in to comment.