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

Set TCP_NODELAY option on TCP sockets #3055

Merged
merged 1 commit into from
Feb 16, 2024
Merged
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
9 changes: 8 additions & 1 deletion sqlx-core/src/net/socket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ pub async fn connect_tcp<Ws: WithSocket>(
use tokio::net::TcpStream;

let stream = TcpStream::connect((host, port)).await?;
stream.set_nodelay(true)?;

return Ok(with_socket.with_socket(stream));
}
Expand All @@ -209,7 +210,13 @@ pub async fn connect_tcp<Ws: WithSocket>(

// Loop through all the Socket Addresses that the hostname resolves to
for socket_addr in (host, port).to_socket_addrs().await? {
match Async::<TcpStream>::connect(socket_addr).await {
let stream = Async::<TcpStream>::connect(socket_addr)
.await
.and_then(|s| {
s.get_ref().set_nodelay(true)?;
Ok(s)
});
match stream {
Ok(stream) => return Ok(with_socket.with_socket(stream)),
Err(e) => last_err = Some(e),
}
Expand Down
Loading