Skip to content

Commit b5a5396

Browse files
author
Hirotaka Azuma
committed
Review fix: Define features regardless of platform and do nothing if not supported.
1 parent a78ce35 commit b5a5396

File tree

4 files changed

+10
-50
lines changed

4 files changed

+10
-50
lines changed

postgres/src/config.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ use tokio_postgres::{Error, Socket};
4949
/// * `keepalives_idle` - The number of seconds of inactivity after which a keepalive message is sent to the server.
5050
/// This option is ignored when connecting with Unix sockets. Defaults to 2 hours.
5151
/// * `keepalives_interval` - The time interval between TCP keepalive probes.
52-
/// This option is ignored when connecting with Unix sockets. Available on neither Redox nor Solaris.
52+
/// This option is ignored when connecting with Unix sockets.
5353
/// * `keepalives_retries` - The maximum number of TCP keepalive probes that will be sent before dropping a connection.
54-
/// This option is ignored when connecting with Unix sockets. Available on neither Redox, Solaris nor Windows.
54+
/// This option is ignored when connecting with Unix sockets.
5555
/// * `target_session_attrs` - Specifies requirements of the session. If set to `read-write`, the client will check that
5656
/// the `transaction_read_write` session parameter is set to `on`. This can be used to connect to the primary server
5757
/// in a database cluster as opposed to the secondary read-only mirrors. Defaults to `all`.
@@ -287,37 +287,25 @@ impl Config {
287287
/// On Windows, this sets the value of the tcp_keepalive struct’s keepaliveinterval field.
288288
///
289289
/// This is ignored for Unix domain sockets, or if the `keepalives` option is disabled.
290-
///
291-
/// Available on neither Redox nor Solaris.
292-
#[cfg(not(any(target_os = "redox", target_os = "solaris")))]
293290
pub fn keepalives_interval(&mut self, keepalives_interval: Duration) -> &mut Config {
294291
self.config.keepalives_interval(keepalives_interval);
295292
self
296293
}
297294

298295
/// Gets the time interval between TCP keepalive probes.
299-
///
300-
/// Available on neither Redox nor Solaris.
301-
#[cfg(not(any(target_os = "redox", target_os = "solaris")))]
302296
pub fn get_keepalives_interval(&self) -> Option<&Duration> {
303297
self.config.get_keepalives_interval()
304298
}
305299

306300
/// Sets the maximum number of TCP keepalive probes that will be sent before dropping a connection.
307301
///
308302
/// This is ignored for Unix domain sockets, or if the `keepalives` option is disabled.
309-
///
310-
/// Available on neither Redox, Solaris nor Windows.
311-
#[cfg(not(any(target_os = "redox", target_os = "solaris", target_os = "windows")))]
312303
pub fn keepalives_retries(&mut self, keepalives_retries: u32) -> &mut Config {
313304
self.config.keepalives_retries(keepalives_retries);
314305
self
315306
}
316307

317308
/// Gets the maximum number of TCP keepalive probes that will be sent before dropping a connection.
318-
///
319-
/// Available on neither Redox, Solaris nor Windows.
320-
#[cfg(not(any(target_os = "redox", target_os = "solaris", target_os = "windows")))]
321309
pub fn get_keepalives_retries(&self) -> Option<&u32> {
322310
self.config.get_keepalives_retries()
323311
}

tokio-postgres/src/config.rs

+8-33
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ pub enum Host {
101101
/// * `keepalives_idle` - The number of seconds of inactivity after which a keepalive message is sent to the server.
102102
/// This option is ignored when connecting with Unix sockets. Defaults to 2 hours.
103103
/// * `keepalives_interval` - The time interval between TCP keepalive probes.
104-
/// This option is ignored when connecting with Unix sockets. Available on neither Redox nor Solaris.
104+
/// This option is ignored when connecting with Unix sockets.
105105
/// * `keepalives_retries` - The maximum number of TCP keepalive probes that will be sent before dropping a connection.
106-
/// This option is ignored when connecting with Unix sockets. Available on neither Redox, Solaris nor Windows.
106+
/// This option is ignored when connecting with Unix sockets.
107107
/// * `target_session_attrs` - Specifies requirements of the session. If set to `read-write`, the client will check that
108108
/// the `transaction_read_write` session parameter is set to `on`. This can be used to connect to the primary server
109109
/// in a database cluster as opposed to the secondary read-only mirrors. Defaults to `all`.
@@ -177,9 +177,7 @@ impl Config {
177177
pub fn new() -> Config {
178178
let keepalive_config = KeepaliveConfig {
179179
idle: Duration::from_secs(2 * 60 * 60),
180-
#[cfg(not(any(target_os = "redox", target_os = "solaris")))]
181180
interval: None,
182-
#[cfg(not(any(target_os = "redox", target_os = "solaris", target_os = "windows")))]
183181
retries: None,
184182
};
185183
Config {
@@ -373,37 +371,25 @@ impl Config {
373371
/// On Windows, this sets the value of the tcp_keepalive struct’s keepaliveinterval field.
374372
///
375373
/// This is ignored for Unix domain sockets, or if the `keepalives` option is disabled.
376-
///
377-
/// Available on neither Redox nor Solaris.
378-
#[cfg(not(any(target_os = "redox", target_os = "solaris")))]
379374
pub fn keepalives_interval(&mut self, keepalives_interval: Duration) -> &mut Config {
380375
self.keepalive_config.interval = Some(keepalives_interval);
381376
self
382377
}
383378

384379
/// Gets the time interval between TCP keepalive probes.
385-
///
386-
/// Available on neither Redox nor Solaris.
387-
#[cfg(not(any(target_os = "redox", target_os = "solaris")))]
388380
pub fn get_keepalives_interval(&self) -> Option<&Duration> {
389381
self.keepalive_config.interval.as_ref()
390382
}
391383

392384
/// Sets the maximum number of TCP keepalive probes that will be sent before dropping a connection.
393385
///
394386
/// This is ignored for Unix domain sockets, or if the `keepalives` option is disabled.
395-
///
396-
/// Available on neither Redox, Solaris nor Windows.
397-
#[cfg(not(any(target_os = "redox", target_os = "solaris", target_os = "windows")))]
398387
pub fn keepalives_retries(&mut self, keepalives_retries: u32) -> &mut Config {
399388
self.keepalive_config.retries = Some(keepalives_retries);
400389
self
401390
}
402391

403392
/// Gets the maximum number of TCP keepalive probes that will be sent before dropping a connection.
404-
///
405-
/// Available on neither Redox, Solaris nor Windows.
406-
#[cfg(not(any(target_os = "redox", target_os = "solaris", target_os = "windows")))]
407393
pub fn get_keepalives_retries(&self) -> Option<&u32> {
408394
self.keepalive_config.retries.as_ref()
409395
}
@@ -502,7 +488,6 @@ impl Config {
502488
self.keepalives_idle(Duration::from_secs(keepalives_idle as u64));
503489
}
504490
}
505-
#[cfg(not(any(target_os = "redox", target_os = "solaris")))]
506491
"keepalives_interval" => {
507492
let keepalives_interval = value.parse::<i64>().map_err(|_| {
508493
Error::config_parse(Box::new(InvalidValue("keepalives_interval")))
@@ -511,7 +496,6 @@ impl Config {
511496
self.keepalives_interval(Duration::from_secs(keepalives_interval as u64));
512497
}
513498
}
514-
#[cfg(not(any(target_os = "redox", target_os = "solaris", target_os = "windows")))]
515499
"keepalives_retries" => {
516500
let keepalives_retries = value.parse::<u32>().map_err(|_| {
517501
Error::config_parse(Box::new(InvalidValue("keepalives_retries")))
@@ -601,8 +585,8 @@ impl fmt::Debug for Config {
601585
}
602586
}
603587

604-
let mut ds = f.debug_struct("Config");
605-
ds.field("user", &self.user)
588+
f.debug_struct("Config")
589+
.field("user", &self.user)
606590
.field("password", &self.password.as_ref().map(|_| Redaction {}))
607591
.field("dbname", &self.dbname)
608592
.field("options", &self.options)
@@ -612,19 +596,10 @@ impl fmt::Debug for Config {
612596
.field("port", &self.port)
613597
.field("connect_timeout", &self.connect_timeout)
614598
.field("keepalives", &self.keepalives)
615-
.field("keepalives_idle", &self.keepalive_config.idle);
616-
617-
#[cfg(not(any(target_os = "redox", target_os = "solaris")))]
618-
{
619-
ds.field("keepalives_interval", &self.keepalive_config.interval);
620-
}
621-
622-
#[cfg(not(any(target_os = "redox", target_os = "solaris", target_os = "windows")))]
623-
{
624-
ds.field("keepalives_retries", &self.keepalive_config.retries);
625-
}
626-
627-
ds.field("target_session_attrs", &self.target_session_attrs)
599+
.field("keepalives_idle", &self.keepalive_config.idle)
600+
.field("keepalives_interval", &self.keepalive_config.interval)
601+
.field("keepalives_retries", &self.keepalive_config.retries)
602+
.field("target_session_attrs", &self.target_session_attrs)
628603
.field("channel_binding", &self.channel_binding)
629604
.finish()
630605
}

tokio-postgres/src/keepalive.rs

-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ use std::time::Duration;
44
#[derive(Clone, PartialEq, Eq)]
55
pub(crate) struct KeepaliveConfig {
66
pub idle: Duration,
7-
#[cfg(not(any(target_os = "redox", target_os = "solaris")))]
87
pub interval: Option<Duration>,
9-
#[cfg(not(any(target_os = "redox", target_os = "solaris", target_os = "windows")))]
108
pub retries: Option<u32>,
119
}
1210

tokio-postgres/tests/test/parse.rs

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ fn settings() {
3737
}
3838

3939
#[test]
40-
#[cfg(not(any(target_os = "redox", target_os = "solaris", target_os = "windows")))]
4140
fn keepalive_settings() {
4241
check(
4342
"keepalives=1 keepalives_idle=15 keepalives_interval=5 keepalives_retries=9",

0 commit comments

Comments
 (0)