Skip to content

Commit 205117b

Browse files
authored
Add support for curl_easy_upkeep (#378)
Add feature-gated support for curl_easy_upkeep, introduced in 7.62.0
1 parent b0fb7fb commit 205117b

File tree

7 files changed

+54
-0
lines changed

7 files changed

+54
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ static-ssl = ["curl-sys/static-ssl"]
4848
force-system-lib-on-osx = ['curl-sys/force-system-lib-on-osx']
4949
protocol-ftp = ["curl-sys/protocol-ftp"]
5050
zlib-ng-compat = ["curl-sys/zlib-ng-compat", "static-curl"]
51+
upkeep_7_62_0 = ["curl-sys/upkeep_7_62_0"]
5152

5253
[[test]]
5354
name = "atexit"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ with various Cargo features:
128128
- `static-curl`: Use a bundled libcurl version and statically link to it. Disabled by default.
129129
- `static-ssl`: Use a bundled OpenSSL version and statically link to it. Only applies on platforms that use OpenSSL. Disabled by default.
130130
- `spnego`: Enable SPNEGO support. Disabled by default.
131+
- `upkeep_7_62_0`: Enable curl_easy_upkeep() support, introduced in curl 7.62.0. Disabled by default.
131132

132133
## Version Support
133134

curl-sys/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ spnego = []
5252
force-system-lib-on-osx = []
5353
protocol-ftp = []
5454
zlib-ng-compat = ["libz-sys/zlib-ng", "static-curl"]
55+
upkeep_7_62_0 = []

curl-sys/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,9 @@ extern "C" {
10301030
n: *mut size_t,
10311031
) -> CURLcode;
10321032

1033+
#[cfg(feature = "upkeep_7_62_0")]
1034+
pub fn curl_easy_upkeep(curl: *mut CURL) -> CURLcode;
1035+
10331036
pub fn curl_multi_init() -> *mut CURLM;
10341037
pub fn curl_multi_add_handle(multi_handle: *mut CURLM, curl_handle: *mut CURL) -> CURLMcode;
10351038
pub fn curl_multi_remove_handle(multi_handle: *mut CURLM, curl_handle: *mut CURL) -> CURLMcode;

src/easy/handle.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,12 @@ impl Easy {
12561256
}
12571257
}
12581258

1259+
/// Same as [`Easy2::upkeep`](struct.Easy2.html#method.upkeep)
1260+
#[cfg(feature = "upkeep_7_62_0")]
1261+
pub fn upkeep(&self) -> Result<(), Error> {
1262+
self.inner.upkeep()
1263+
}
1264+
12591265
/// Same as [`Easy2::unpause_read`](struct.Easy2.html#method.unpause_read)
12601266
pub fn unpause_read(&self) -> Result<(), Error> {
12611267
self.inner.unpause_read()
@@ -1504,6 +1510,12 @@ impl<'easy, 'data> Transfer<'easy, 'data> {
15041510
self.easy.do_perform()
15051511
}
15061512

1513+
/// Same as `Easy::upkeep`
1514+
#[cfg(feature = "upkeep_7_62_0")]
1515+
pub fn upkeep(&self) -> Result<(), Error> {
1516+
self.easy.upkeep()
1517+
}
1518+
15071519
/// Same as `Easy::unpause_read`.
15081520
pub fn unpause_read(&self) -> Result<(), Error> {
15091521
self.easy.unpause_read()

src/easy/handler.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2737,6 +2737,21 @@ impl<H> Easy2<H> {
27372737
ret
27382738
}
27392739

2740+
/// Some protocols have "connection upkeep" mechanisms. These mechanisms
2741+
/// usually send some traffic on existing connections in order to keep them
2742+
/// alive; this can prevent connections from being closed due to overzealous
2743+
/// firewalls, for example.
2744+
///
2745+
/// Currently the only protocol with a connection upkeep mechanism is
2746+
/// HTTP/2: when the connection upkeep interval is exceeded and upkeep() is
2747+
/// called, an HTTP/2 PING frame is sent on the connection.
2748+
#[cfg(feature = "upkeep_7_62_0")]
2749+
pub fn upkeep(&self) -> Result<(), Error> {
2750+
let ret = unsafe { self.cvt(curl_sys::curl_easy_upkeep(self.inner.handle)) };
2751+
panic::propagate();
2752+
return ret;
2753+
}
2754+
27402755
/// Unpause reading on a connection.
27412756
///
27422757
/// Using this function, you can explicitly unpause a connection that was

tests/easy.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,3 +828,24 @@ fn check_unix_socket() {
828828
t!(h.post_fields_copy(b"data\n"));
829829
t!(h.perform());
830830
}
831+
832+
#[cfg(feature = "upkeep_7_62_0")]
833+
#[test]
834+
fn test_upkeep() {
835+
let s = Server::new();
836+
s.receive(
837+
"\
838+
GET / HTTP/1.1\r\n\
839+
Host: 127.0.0.1:$PORT\r\n\
840+
Accept: */*\r\n\
841+
\r\n",
842+
);
843+
s.send("HTTP/1.1 200 OK\r\n\r\n");
844+
845+
let mut handle = handle();
846+
t!(handle.url(&s.url("/")));
847+
t!(handle.perform());
848+
849+
// Ensure that upkeep can be called on the handle without problem.
850+
t!(handle.upkeep());
851+
}

0 commit comments

Comments
 (0)