Skip to content

Commit

Permalink
Support TCP_NODELAY and use it by default
Browse files Browse the repository at this point in the history
  • Loading branch information
athre0z committed Sep 18, 2024
1 parent f66b178 commit 9756c43
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion klickhouse/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ pub struct ClientOptions {
pub username: String,
pub password: String,
pub default_database: String,
pub tcp_nodelay: bool,
}

impl Default for ClientOptions {
Expand All @@ -250,6 +251,7 @@ impl Default for ClientOptions {
username: "default".to_string(),
password: String::new(),
default_database: String::new(),
tcp_nodelay: true,
}
}
}
Expand All @@ -271,7 +273,9 @@ impl Client {

/// Connects to a specific socket address over plaintext TCP for Clickhouse.
pub async fn connect<A: ToSocketAddrs>(destination: A, options: ClientOptions) -> Result<Self> {
let (read, writer) = TcpStream::connect(destination).await?.into_split();
let stream = TcpStream::connect(destination).await?;
stream.set_nodelay(options.tcp_nodelay)?;
let (read, writer) = stream.into_split();
Self::connect_stream(read, writer, options).await
}

Expand All @@ -284,6 +288,7 @@ impl Client {
connector: &tokio_rustls::TlsConnector,
) -> Result<Self> {
let stream = TcpStream::connect(destination).await?;
stream.set_nodelay(options.tcp_nodelay)?;
let tls_stream = connector.connect(name, stream).await?;
let (read, writer) = tokio::io::split(tls_stream);
Self::connect_stream(read, writer, options).await
Expand Down

0 comments on commit 9756c43

Please sign in to comment.