Skip to content

Commit eedf4d0

Browse files
committed
Change tcp_keepalive to take a std::Duration
1 parent 75c51d9 commit eedf4d0

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
77
name = "mysql_async"
88
readme = "README.md"
99
repository = "https://github.com/blackbeam/mysql_async"
10-
version = "0.36.1"
10+
version = "0.37.0"
1111
exclude = ["test/*"]
1212
edition = "2021"
1313
categories = ["asynchronous", "database"]

src/conn/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -957,9 +957,7 @@ impl Conn {
957957
#[cfg(not(unix))]
958958
return Err(crate::DriverError::NamedPipesDisabled.into());
959959
} else {
960-
let keepalive = opts
961-
.tcp_keepalive()
962-
.map(|x| std::time::Duration::from_millis(x.into()));
960+
let keepalive = opts.tcp_keepalive();
963961
Stream::connect_tcp(opts.hostport_or_url(), keepalive).await?
964962
};
965963

src/opts/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,8 @@ pub(crate) struct MysqlOpts {
575575
/// Database name (defaults to `None`).
576576
db_name: Option<String>,
577577

578-
/// TCP keep alive timeout in milliseconds (defaults to `None`).
579-
tcp_keepalive: Option<u32>,
578+
/// TCP keep alive timeout (defaults to `None`).
579+
tcp_keepalive: Option<Duration>,
580580

581581
/// Whether to enable `TCP_NODELAY` (defaults to `true`).
582582
///
@@ -804,7 +804,7 @@ impl Opts {
804804
/// assert_eq!(opts.tcp_keepalive(), Some(10_000));
805805
/// # Ok(()) }
806806
/// ```
807-
pub fn tcp_keepalive(&self) -> Option<u32> {
807+
pub fn tcp_keepalive(&self) -> Option<Duration> {
808808
self.inner.mysql_opts.tcp_keepalive
809809
}
810810

@@ -1353,8 +1353,8 @@ impl OptsBuilder {
13531353
}
13541354

13551355
/// Defines `tcp_keepalive` option. See [`Opts::tcp_keepalive`].
1356-
pub fn tcp_keepalive<T: Into<u32>>(mut self, tcp_keepalive: Option<T>) -> Self {
1357-
self.opts.tcp_keepalive = tcp_keepalive.map(Into::into);
1356+
pub fn tcp_keepalive(mut self, tcp_keepalive: Option<Duration>) -> Self {
1357+
self.opts.tcp_keepalive = tcp_keepalive;
13581358
self
13591359
}
13601360

@@ -1773,7 +1773,7 @@ fn mysqlopts_from_url(url: &Url) -> std::result::Result<MysqlOpts, UrlError> {
17731773
}
17741774
} else if key == "tcp_keepalive" {
17751775
match u32::from_str(&value) {
1776-
Ok(value) => opts.tcp_keepalive = Some(value),
1776+
Ok(value) => opts.tcp_keepalive = Some(Duration::from_millis(value.into())),
17771777
_ => {
17781778
return Err(UrlError::InvalidParamValue {
17791779
param: "tcp_keepalive_ms".into(),

0 commit comments

Comments
 (0)