re-enable SO_LINGER(0)

This commit is contained in:
Christien Rioux 2024-07-20 18:39:24 -04:00
parent e568c39efb
commit 39d8b397fa
3 changed files with 32 additions and 32 deletions

View File

@ -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;

View File

@ -91,9 +91,9 @@ pub fn new_default_tcp_socket(domain: Domain) -> io::Result<Socket> {
#[instrument(level = "trace", ret)]
pub fn new_shared_tcp_socket(domain: Domain) -> io::Result<Socket> {
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);
}

View File

@ -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