Set TCP_NODELAY option on TCP sockets (#3055)

This commit is contained in:
Mirek Klimos 2024-02-15 22:26:52 -08:00 committed by GitHub
parent d7cbf940c3
commit 4c057a0628
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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));
}
@ -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),
}