Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support build on wasm32 #1146

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tokio-postgres/src/cancel_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ where
config.port,
config.connect_timeout,
config.tcp_user_timeout,
#[cfg(not(target_arch = "wasm32"))]
config.keepalive.as_ref(),
)
.await?;
Expand Down
5 changes: 3 additions & 2 deletions tokio-postgres/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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};
Expand Down Expand Up @@ -160,6 +160,7 @@ pub(crate) struct SocketConfig {
pub port: u16,
pub connect_timeout: Option<Duration>,
pub tcp_user_timeout: Option<Duration>,
#[cfg(not(target_arch = "wasm32"))]
pub keepalive: Option<KeepaliveConfig>,
}

Expand Down
2 changes: 2 additions & 0 deletions tokio-postgres/src/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion tokio-postgres/src/connect_socket.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Socket, Error> {
match addr {
Addr::Tcp(ip) => {
Expand All @@ -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")]
{
Expand All @@ -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))
Expand Down