Skip to content

Commit 3ae16ec

Browse files
authored
Merge pull request #163 from alexcrichton/keepalive
Bind TCP keepalive-related options
2 parents 56e8e8d + 60b3649 commit 3ae16ec

File tree

3 files changed

+46
-31
lines changed

3 files changed

+46
-31
lines changed

curl-sys/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,9 +589,9 @@ pub const CURLOPT_CLOSESOCKETDATA: CURLoption = CURLOPTTYPE_OBJECTPOINT + 209;
589589
pub const CURLOPT_GSSAPI_DELEGATION: CURLoption = CURLOPTTYPE_LONG + 210;
590590
// pub const CURLOPT_DNS_SERVERS: CURLoption = CURLOPTTYPE_OBJECTPOINT + 211;
591591
// pub const CURLOPT_ACCEPTTIMEOUT_MS: CURLoption = CURLOPTTYPE_LONG + 212;
592-
// pub const CURLOPT_TCP_KEEPALIVE: CURLoption = CURLOPTTYPE_LONG + 213;
593-
// pub const CURLOPT_TCP_KEEPIDLE: CURLoption = CURLOPTTYPE_LONG + 214;
594-
// pub const CURLOPT_TCP_KEEPINTVL: CURLoption = CURLOPTTYPE_LONG + 215;
592+
pub const CURLOPT_TCP_KEEPALIVE: CURLoption = CURLOPTTYPE_LONG + 213;
593+
pub const CURLOPT_TCP_KEEPIDLE: CURLoption = CURLOPTTYPE_LONG + 214;
594+
pub const CURLOPT_TCP_KEEPINTVL: CURLoption = CURLOPTTYPE_LONG + 215;
595595
pub const CURLOPT_SSL_OPTIONS: CURLoption = CURLOPTTYPE_LONG + 216;
596596
// pub const CURLOPT_MAIL_AUTH: CURLoption = CURLOPTTYPE_OBJECTPOINT + 217;
597597
// pub const CURLOPT_SASL_IR: CURLoption = CURLOPTTYPE_LONG + 218;

src/easy/handle.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,21 @@ impl Easy {
600600
self.inner.tcp_nodelay(enable)
601601
}
602602

603+
/// Same as [`Easy2::tcp_keepalive`](struct.Easy2.html#method.tcp_keepalive)
604+
pub fn tcp_keepalive(&mut self, enable: bool) -> Result<(), Error> {
605+
self.inner.tcp_keepalive(enable)
606+
}
607+
608+
/// Same as [`Easy2::tcp_keepintvl`](struct.Easy2.html#method.tcp_keepalive)
609+
pub fn tcp_keepintvl(&mut self, dur: Duration) -> Result<(), Error> {
610+
self.inner.tcp_keepintvl(dur)
611+
}
612+
613+
/// Same as [`Easy2::tcp_keepidle`](struct.Easy2.html#method.tcp_keepidle)
614+
pub fn tcp_keepidle(&mut self, dur: Duration) -> Result<(), Error> {
615+
self.inner.tcp_keepidle(dur)
616+
}
617+
603618
/// Same as [`Easy2::address_scope`](struct.Easy2.html#method.address_scope)
604619
pub fn address_scope(&mut self, scope: u32) -> Result<(), Error> {
605620
self.inner.address_scope(scope)

src/easy/handler.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -923,35 +923,35 @@ impl<H> Easy2<H> {
923923
self.setopt_long(curl_sys::CURLOPT_TCP_NODELAY, enable as c_long)
924924
}
925925

926-
// /// Configures whether TCP keepalive probes will be sent.
927-
// ///
928-
// /// The delay and frequency of these probes is controlled by `tcp_keepidle`
929-
// /// and `tcp_keepintvl`.
930-
// ///
931-
// /// By default this option is `false` and corresponds to
932-
// /// `CURLOPT_TCP_KEEPALIVE`.
933-
// pub fn tcp_keepalive(&mut self, enable: bool) -> Result<(), Error> {
934-
// self.setopt_long(curl_sys::CURLOPT_TCP_KEEPALIVE, enable as c_long)
935-
// }
926+
/// Configures whether TCP keepalive probes will be sent.
927+
///
928+
/// The delay and frequency of these probes is controlled by `tcp_keepidle`
929+
/// and `tcp_keepintvl`.
930+
///
931+
/// By default this option is `false` and corresponds to
932+
/// `CURLOPT_TCP_KEEPALIVE`.
933+
pub fn tcp_keepalive(&mut self, enable: bool) -> Result<(), Error> {
934+
self.setopt_long(curl_sys::CURLOPT_TCP_KEEPALIVE, enable as c_long)
935+
}
936936

937-
// /// Configures the TCP keepalive idle time wait.
938-
// ///
939-
// /// This is the delay, after which the connection is idle, keepalive probes
940-
// /// will be sent. Not all operating systems support this.
941-
// ///
942-
// /// By default this corresponds to `CURLOPT_TCP_KEEPIDLE`.
943-
// pub fn tcp_keepidle(&mut self, amt: Duration) -> Result<(), Error> {
944-
// self.setopt_long(curl_sys::CURLOPT_TCP_KEEPIDLE,
945-
// amt.as_secs() as c_long)
946-
// }
947-
//
948-
// /// Configures the delay between keepalive probes.
949-
// ///
950-
// /// By default this corresponds to `CURLOPT_TCP_KEEPINTVL`.
951-
// pub fn tcp_keepintvl(&mut self, amt: Duration) -> Result<(), Error> {
952-
// self.setopt_long(curl_sys::CURLOPT_TCP_KEEPINTVL,
953-
// amt.as_secs() as c_long)
954-
// }
937+
/// Configures the TCP keepalive idle time wait.
938+
///
939+
/// This is the delay, after which the connection is idle, keepalive probes
940+
/// will be sent. Not all operating systems support this.
941+
///
942+
/// By default this corresponds to `CURLOPT_TCP_KEEPIDLE`.
943+
pub fn tcp_keepidle(&mut self, amt: Duration) -> Result<(), Error> {
944+
self.setopt_long(curl_sys::CURLOPT_TCP_KEEPIDLE,
945+
amt.as_secs() as c_long)
946+
}
947+
948+
/// Configures the delay between keepalive probes.
949+
///
950+
/// By default this corresponds to `CURLOPT_TCP_KEEPINTVL`.
951+
pub fn tcp_keepintvl(&mut self, amt: Duration) -> Result<(), Error> {
952+
self.setopt_long(curl_sys::CURLOPT_TCP_KEEPINTVL,
953+
amt.as_secs() as c_long)
954+
}
955955

956956
/// Configures the scope for local IPv6 addresses.
957957
///

0 commit comments

Comments
 (0)