Skip to content

Commit 9722097

Browse files
sagebindalexcrichton
authored andcommitted
Bindings for CURLMOPT_MAXCONNECTS and CURLMOPT_MAX_TOTAL_CONNECTIONS (#301)
Add bindings for `CURLMOPT_MAXCONNECTS` and `CURLMOPT_MAX_TOTAL_CONNECTIONS`. Also export more `CURLM` options in `curl-sys`, and add a getter for accessing the underlying `CURLM` pointer.
1 parent fd2b973 commit 9722097

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

curl-sys/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -899,14 +899,14 @@ pub const CURLMOPT_SOCKETDATA: CURLMoption = CURLOPTTYPE_OBJECTPOINT + 2;
899899
pub const CURLMOPT_PIPELINING: CURLMoption = CURLOPTTYPE_LONG + 3;
900900
pub const CURLMOPT_TIMERFUNCTION: CURLMoption = CURLOPTTYPE_FUNCTIONPOINT + 4;
901901
pub const CURLMOPT_TIMERDATA: CURLMoption = CURLOPTTYPE_OBJECTPOINT + 5;
902-
// pub const CURLMOPT_MAXCONNECTS: CURLMoption = CURLOPTTYPE_LONG + 6;
902+
pub const CURLMOPT_MAXCONNECTS: CURLMoption = CURLOPTTYPE_LONG + 6;
903903
pub const CURLMOPT_MAX_HOST_CONNECTIONS: CURLMoption = CURLOPTTYPE_LONG + 7;
904904
pub const CURLMOPT_MAX_PIPELINE_LENGTH: CURLMoption = CURLOPTTYPE_LONG + 8;
905-
// pub const CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE: CURLMoption = CURLOPTTYPE_OFF_T + 9;
906-
// pub const CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE: CURLMoption = CURLOPTTYPE_OFF_T + 10;
907-
// pub const CURLMOPT_PIPELINING_SITE_BL: CURLMoption = CURLOPTTYPE_OBJECTPOINT + 11;
908-
// pub const CURLMOPT_PIPELINING_SERVER_BL: CURLMoption = CURLOPTTYPE_OBJECTPOINT + 12;
909-
// pub const CURLMOPT_MAX_TOTAL_CONNECTIONS: CURLMoption = CURLOPTTYPE_LONG + 13;
905+
pub const CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE: CURLMoption = CURLOPTTYPE_OFF_T + 9;
906+
pub const CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE: CURLMoption = CURLOPTTYPE_OFF_T + 10;
907+
pub const CURLMOPT_PIPELINING_SITE_BL: CURLMoption = CURLOPTTYPE_OBJECTPOINT + 11;
908+
pub const CURLMOPT_PIPELINING_SERVER_BL: CURLMoption = CURLOPTTYPE_OBJECTPOINT + 12;
909+
pub const CURLMOPT_MAX_TOTAL_CONNECTIONS: CURLMoption = CURLOPTTYPE_LONG + 13;
910910

911911
// These enums are for use with the CURLMOPT_PIPELINING option.
912912
pub const CURLPIPE_NOTHING: c_long = 0;

src/multi.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,37 @@ impl Multi {
299299
self.setopt_long(curl_sys::CURLMOPT_MAX_HOST_CONNECTIONS, val as c_long)
300300
}
301301

302+
/// Sets the max simultaneously open connections.
303+
///
304+
/// The set number will be used as the maximum number of simultaneously open
305+
/// connections in total using this multi handle. For each new session,
306+
/// libcurl will open a new connection up to the limit set by the provided
307+
/// value. When the limit is reached, the sessions will be pending until
308+
/// there are available connections. If pipelining is enabled, libcurl will
309+
/// try to pipeline or use multiplexing if the host is capable of it.
310+
pub fn set_max_total_connections(&mut self, val: usize) -> Result<(), MultiError> {
311+
self.setopt_long(curl_sys::CURLMOPT_MAX_TOTAL_CONNECTIONS, val as c_long)
312+
}
313+
314+
/// Set size of connection cache.
315+
///
316+
/// The set number will be used as the maximum amount of simultaneously open
317+
/// connections that libcurl may keep in its connection cache after
318+
/// completed use. By default libcurl will enlarge the size for each added
319+
/// easy handle to make it fit 4 times the number of added easy handles.
320+
///
321+
/// By setting this option, you can prevent the cache size from growing
322+
/// beyond the limit set by you.
323+
///
324+
/// When the cache is full, curl closes the oldest one in the cache to
325+
/// prevent the number of open connections from increasing.
326+
///
327+
/// See [`set_max_total_connections`](#method.set_max_total_connections) for
328+
/// limiting the number of active connections.
329+
pub fn set_max_connects(&mut self, val: usize) -> Result<(), MultiError> {
330+
self.setopt_long(curl_sys::CURLMOPT_MAXCONNECTS, val as c_long)
331+
}
332+
302333
/// Sets the pipeline length.
303334
///
304335
/// This sets the max number that will be used as the maximum amount of
@@ -673,6 +704,11 @@ impl Multi {
673704
pub fn close(&self) -> Result<(), MultiError> {
674705
unsafe { cvt(curl_sys::curl_multi_cleanup(self.raw)) }
675706
}
707+
708+
/// Get a pointer to the raw underlying CURLM handle.
709+
pub fn raw(&self) -> *mut curl_sys::CURLM {
710+
self.raw
711+
}
676712
}
677713

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

0 commit comments

Comments
 (0)