diff --git a/tokio-postgres/src/cancel_query.rs b/tokio-postgres/src/cancel_query.rs index 078d4b8b6..b9453dc01 100644 --- a/tokio-postgres/src/cancel_query.rs +++ b/tokio-postgres/src/cancel_query.rs @@ -34,6 +34,7 @@ where config.port, config.connect_timeout, config.tcp_user_timeout, + #[cfg(not(target_arch = "wasm32"))] config.keepalive.as_ref(), ) .await?; diff --git a/tokio-postgres/src/client.rs b/tokio-postgres/src/client.rs index b04f05f88..adb4024d4 100644 --- a/tokio-postgres/src/client.rs +++ b/tokio-postgres/src/client.rs @@ -2,7 +2,7 @@ use crate::codec::{BackendMessages, FrontendMessage}; use crate::config::SslMode; use crate::connection::{Request, RequestMessages}; use crate::copy_out::CopyOutStream; -#[cfg(feature = "runtime")] +#[cfg(all(feature = "runtime", not(target_arch = "wasm32")))] use crate::keepalive::KeepaliveConfig; use crate::query::RowStream; use crate::simple_query::SimpleQueryStream; @@ -27,7 +27,7 @@ use std::collections::HashMap; use std::fmt; #[cfg(feature = "runtime")] use std::net::IpAddr; -#[cfg(feature = "runtime")] +#[cfg(all(feature = "runtime", unix))] use std::path::PathBuf; use std::sync::Arc; use std::task::{Context, Poll}; @@ -160,6 +160,7 @@ pub(crate) struct SocketConfig { pub port: u16, pub connect_timeout: Option, pub tcp_user_timeout: Option, + #[cfg(not(target_arch = "wasm32"))] pub keepalive: Option, } diff --git a/tokio-postgres/src/connect.rs b/tokio-postgres/src/connect.rs index 8189cb91c..7ca3dcb1b 100644 --- a/tokio-postgres/src/connect.rs +++ b/tokio-postgres/src/connect.rs @@ -146,6 +146,7 @@ where port, config.connect_timeout, config.tcp_user_timeout, + #[cfg(not(target_arch = "wasm32"))] if config.keepalives { Some(&config.keepalive_config) } else { @@ -216,6 +217,7 @@ where port, connect_timeout: config.connect_timeout, tcp_user_timeout: config.tcp_user_timeout, + #[cfg(not(target_arch = "wasm32"))] keepalive: if config.keepalives { Some(config.keepalive_config.clone()) } else { diff --git a/tokio-postgres/src/connect_socket.rs b/tokio-postgres/src/connect_socket.rs index f27131178..b9f80c75a 100644 --- a/tokio-postgres/src/connect_socket.rs +++ b/tokio-postgres/src/connect_socket.rs @@ -1,6 +1,8 @@ use crate::client::Addr; +#[cfg(not(target_arch = "wasm32"))] use crate::keepalive::KeepaliveConfig; use crate::{Error, Socket}; +#[cfg(not(target_arch = "wasm32"))] use socket2::{SockRef, TcpKeepalive}; use std::future::Future; use std::io; @@ -17,7 +19,7 @@ pub(crate) async fn connect_socket( #[cfg_attr(not(target_os = "linux"), allow(unused_variables))] tcp_user_timeout: Option< Duration, >, - keepalive_config: Option<&KeepaliveConfig>, + #[cfg(not(target_arch = "wasm32"))] keepalive_config: Option<&KeepaliveConfig>, ) -> Result { match addr { Addr::Tcp(ip) => { @@ -26,6 +28,7 @@ pub(crate) async fn connect_socket( stream.set_nodelay(true).map_err(Error::connect)?; + #[cfg(not(target_arch = "wasm32"))] let sock_ref = SockRef::from(&stream); #[cfg(target_os = "linux")] { @@ -34,6 +37,7 @@ pub(crate) async fn connect_socket( .map_err(Error::connect)?; } + #[cfg(not(target_arch = "wasm32"))] if let Some(keepalive_config) = keepalive_config { sock_ref .set_tcp_keepalive(&TcpKeepalive::from(keepalive_config))