From 39d8b397fae843f9c4c058ca0276ae3bac736c34 Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Sat, 20 Jul 2024 18:39:24 -0400 Subject: [PATCH] re-enable SO_LINGER(0) --- .../src/network_manager/native/network_tcp.rs | 54 +++++++++---------- .../native/protocol/sockets.rs | 6 +-- .../src/network_manager/network_connection.rs | 4 +- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/veilid-core/src/network_manager/native/network_tcp.rs b/veilid-core/src/network_manager/native/network_tcp.rs index aeff8359..d47a4da3 100644 --- a/veilid-core/src/network_manager/native/network_tcp.rs +++ b/veilid-core/src/network_manager/native/network_tcp.rs @@ -132,33 +132,33 @@ impl Network { } }; - // #[cfg(all(feature = "rt-async-std", unix))] - // { - // // async-std does not directly support linger on TcpStream yet - // use std::os::fd::{AsRawFd, FromRawFd}; - // if let Err(e) = unsafe { socket2::Socket::from_raw_fd(tcp_stream.as_raw_fd()) } - // .set_linger(Some(core::time::Duration::from_secs(0))) - // { - // log_net!(debug "Couldn't set TCP linger: {}", e); - // return; - // } - // } - // #[cfg(all(feature = "rt-async-std", windows))] - // { - // // async-std does not directly support linger on TcpStream yet - // use std::os::windows::io::{AsRawSocket, FromRawSocket}; - // if let Err(e) = unsafe { socket2::Socket::from_raw_socket(tcp_stream.as_raw_socket()) } - // .set_linger(Some(core::time::Duration::from_secs(0))) - // { - // log_net!(debug "Couldn't set TCP linger: {}", e); - // return; - // } - // } - // #[cfg(not(feature = "rt-async-std"))] - // if let Err(e) = tcp_stream.set_linger(Some(core::time::Duration::from_secs(0))) { - // log_net!(debug "Couldn't set TCP linger: {}", e); - // return; - // } + #[cfg(all(feature = "rt-async-std", unix))] + { + // async-std does not directly support linger on TcpStream yet + use std::os::fd::{AsRawFd, FromRawFd}; + if let Err(e) = unsafe { socket2::Socket::from_raw_fd(tcp_stream.as_raw_fd()) } + .set_linger(Some(core::time::Duration::from_secs(0))) + { + log_net!(debug "Couldn't set TCP linger: {}", e); + return; + } + } + #[cfg(all(feature = "rt-async-std", windows))] + { + // async-std does not directly support linger on TcpStream yet + use std::os::windows::io::{AsRawSocket, FromRawSocket}; + if let Err(e) = unsafe { socket2::Socket::from_raw_socket(tcp_stream.as_raw_socket()) } + .set_linger(Some(core::time::Duration::from_secs(0))) + { + log_net!(debug "Couldn't set TCP linger: {}", e); + return; + } + } + #[cfg(not(feature = "rt-async-std"))] + if let Err(e) = tcp_stream.set_linger(Some(core::time::Duration::from_secs(0))) { + log_net!(debug "Couldn't set TCP linger: {}", e); + return; + } if let Err(e) = tcp_stream.set_nodelay(true) { log_net!(debug "Couldn't set TCP nodelay: {}", e); return; diff --git a/veilid-core/src/network_manager/native/protocol/sockets.rs b/veilid-core/src/network_manager/native/protocol/sockets.rs index c8a18f9e..da100d6f 100644 --- a/veilid-core/src/network_manager/native/protocol/sockets.rs +++ b/veilid-core/src/network_manager/native/protocol/sockets.rs @@ -91,9 +91,9 @@ pub fn new_default_tcp_socket(domain: Domain) -> io::Result { #[instrument(level = "trace", ret)] pub fn new_shared_tcp_socket(domain: Domain) -> io::Result { let socket = Socket::new(domain, Type::STREAM, Some(Protocol::TCP))?; - // if let Err(e) = socket.set_linger(Some(core::time::Duration::from_secs(0))) { - // log_net!(error "Couldn't set TCP linger: {}", e); - // } + if let Err(e) = socket.set_linger(Some(core::time::Duration::from_secs(0))) { + log_net!(error "Couldn't set TCP linger: {}", e); + } if let Err(e) = socket.set_nodelay(true) { log_net!(error "Couldn't set TCP nodelay: {}", e); } diff --git a/veilid-core/src/network_manager/network_connection.rs b/veilid-core/src/network_manager/network_connection.rs index 4f45a8a9..6acc0117 100644 --- a/veilid-core/src/network_manager/network_connection.rs +++ b/veilid-core/src/network_manager/network_connection.rs @@ -265,7 +265,7 @@ impl NetworkConnection { // Connection receiver loop #[allow(clippy::too_many_arguments)] - //#[instrument(level="trace", target="net", skip_all)] + #[instrument(level="trace", target="net", skip_all)] fn process_connection( connection_manager: ConnectionManager, local_stop_token: StopToken, @@ -299,7 +299,7 @@ impl NetworkConnection { }; let timer = MutableFuture::new(new_timer()); - unord.push(system_boxed(timer.clone().in_current_span())); + unord.push(system_boxed(timer.clone())); loop { // Add another message sender future if necessary