mirror of
https://gitlab.com/veilid/veilid.git
synced 2024-10-01 01:26:08 -04:00
turn off linger
This commit is contained in:
parent
2c4883ee85
commit
23f47be357
@ -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;
|
||||
|
@ -55,15 +55,15 @@ impl ProtocolNetworkConnection {
|
||||
}
|
||||
}
|
||||
|
||||
// pub async fn close(&self) -> io::Result<NetworkResult<()>> {
|
||||
// match self {
|
||||
// Self::Dummy(d) => d.close(),
|
||||
// Self::RawTcp(t) => t.close().await,
|
||||
// Self::WsAccepted(w) => w.close().await,
|
||||
// Self::Ws(w) => w.close().await,
|
||||
// Self::Wss(w) => w.close().await,
|
||||
// }
|
||||
// }
|
||||
pub async fn close(&self) -> io::Result<NetworkResult<()>> {
|
||||
match self {
|
||||
Self::Dummy(d) => d.close(),
|
||||
Self::RawTcp(t) => t.close().await,
|
||||
Self::WsAccepted(w) => w.close().await,
|
||||
Self::Ws(w) => w.close().await,
|
||||
Self::Wss(w) => w.close().await,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn send(&self, message: Vec<u8>) -> io::Result<NetworkResult<()>> {
|
||||
match self {
|
||||
|
@ -112,9 +112,9 @@ pub fn new_unbound_tcp_socket(domain: Domain) -> io::Result<Socket> {
|
||||
#[instrument(level = "trace", ret)]
|
||||
pub fn new_unbound_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);
|
||||
}
|
||||
@ -148,9 +148,9 @@ pub fn new_bound_first_tcp_socket(local_address: SocketAddr) -> io::Result<Socke
|
||||
let domain = Domain::for_address(local_address);
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -22,25 +22,30 @@ impl RawTcpNetworkConnection {
|
||||
self.descriptor
|
||||
}
|
||||
|
||||
// #[instrument(level = "trace", err, skip(self))]
|
||||
// pub async fn close(&mut self) -> io::Result<NetworkResult<()>> {
|
||||
// // Make an attempt to flush the stream
|
||||
// self.stream.clone().close().await?;
|
||||
// // Then shut down the write side of the socket to effect a clean close
|
||||
// cfg_if! {
|
||||
// if #[cfg(feature="rt-async-std")] {
|
||||
// self.tcp_stream
|
||||
// .shutdown(async_std::net::Shutdown::Write)
|
||||
// } else if #[cfg(feature="rt-tokio")] {
|
||||
// use tokio::io::AsyncWriteExt;
|
||||
// self.tcp_stream.get_mut()
|
||||
// .shutdown()
|
||||
// .await
|
||||
// } else {
|
||||
// compile_error!("needs executor implementation")
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
#[cfg_attr(
|
||||
feature = "verbose-tracing",
|
||||
instrument(level = "trace", err, skip(self))
|
||||
)]
|
||||
pub async fn close(&self) -> io::Result<NetworkResult<()>> {
|
||||
// Make an attempt to flush the stream
|
||||
self.stream.clone().close().await?;
|
||||
Ok(NetworkResult::value(()))
|
||||
|
||||
// // Then shut down the write side of the socket to effect a clean close
|
||||
// cfg_if! {
|
||||
// if #[cfg(feature="rt-async-std")] {
|
||||
// self.tcp_stream
|
||||
// .shutdown(async_std::net::Shutdown::Write)
|
||||
// } else if #[cfg(feature="rt-tokio")] {
|
||||
// use tokio::io::AsyncWriteExt;
|
||||
// self.tcp_stream.get_mut()
|
||||
// .shutdown()
|
||||
// .await
|
||||
// } else {
|
||||
// compile_error!("needs executor implementation")
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
async fn send_internal(
|
||||
stream: &mut AsyncPeekStream,
|
||||
|
@ -77,15 +77,24 @@ where
|
||||
self.descriptor
|
||||
}
|
||||
|
||||
// #[instrument(level = "trace", err, skip(self))]
|
||||
// pub async fn close(&self) -> io::Result<()> {
|
||||
// // Make an attempt to flush the stream
|
||||
// self.stream.clone().close().await.map_err(to_io_error_other)?;
|
||||
// // Then forcibly close the socket
|
||||
// self.tcp_stream
|
||||
// .shutdown(Shutdown::Both)
|
||||
// .map_err(to_io_error_other)
|
||||
// }
|
||||
#[cfg_attr(
|
||||
feature = "verbose-tracing",
|
||||
instrument(level = "trace", err, skip(self))
|
||||
)]
|
||||
pub async fn close(&self) -> io::Result<NetworkResult<()>> {
|
||||
// Make an attempt to flush the stream
|
||||
self.stream
|
||||
.clone()
|
||||
.close()
|
||||
.await
|
||||
.map_err(to_io_error_other)?;
|
||||
// // Then forcibly close the socket
|
||||
// self.tcp_stream
|
||||
// .shutdown(Shutdown::Both)
|
||||
// .map_err(to_io_error_other)
|
||||
|
||||
Ok(NetworkResult::value(()))
|
||||
}
|
||||
|
||||
#[cfg_attr(feature="verbose-tracing", instrument(level = "trace", err, skip(self, message), fields(network_result, message.len = message.len())))]
|
||||
pub async fn send(&self, message: Vec<u8>) -> io::Result<NetworkResult<()>> {
|
||||
|
@ -54,9 +54,9 @@ impl DummyNetworkConnection {
|
||||
pub fn descriptor(&self) -> ConnectionDescriptor {
|
||||
self.descriptor
|
||||
}
|
||||
// pub fn close(&self) -> io::Result<()> {
|
||||
// Ok(())
|
||||
// }
|
||||
pub fn close(&self) -> io::Result<NetworkResult<()>> {
|
||||
Ok(NetworkResult::Value(()))
|
||||
}
|
||||
pub fn send(&self, _message: Vec<u8>) -> io::Result<NetworkResult<()>> {
|
||||
Ok(NetworkResult::Value(()))
|
||||
}
|
||||
|
@ -41,13 +41,12 @@ impl ProtocolNetworkConnection {
|
||||
Self::Ws(w) => w.descriptor(),
|
||||
}
|
||||
}
|
||||
|
||||
// pub async fn close(&self) -> io::Result<NetworkResult<()>> {
|
||||
// match self {
|
||||
// Self::Dummy(d) => d.close(),
|
||||
// Self::Ws(w) => w.close().await,
|
||||
// }
|
||||
// }
|
||||
pub async fn close(&self) -> io::Result<NetworkResult<()>> {
|
||||
match self {
|
||||
Self::Dummy(d) => d.close(),
|
||||
Self::Ws(w) => w.close().await,
|
||||
}
|
||||
}
|
||||
pub async fn send(&self, message: Vec<u8>) -> io::Result<NetworkResult<()>> {
|
||||
match self {
|
||||
Self::Dummy(d) => d.send(message),
|
||||
|
@ -5,7 +5,7 @@ use std::io;
|
||||
use ws_stream_wasm::*;
|
||||
|
||||
struct WebsocketNetworkConnectionInner {
|
||||
_ws_meta: WsMeta,
|
||||
ws_meta: WsMeta,
|
||||
ws_stream: CloneStream<WsStream>,
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ impl WebsocketNetworkConnection {
|
||||
Self {
|
||||
descriptor,
|
||||
inner: Arc::new(WebsocketNetworkConnectionInner {
|
||||
_ws_meta: ws_meta,
|
||||
ws_meta,
|
||||
ws_stream: CloneStream::new(ws_stream),
|
||||
}),
|
||||
}
|
||||
@ -59,10 +59,14 @@ impl WebsocketNetworkConnection {
|
||||
self.descriptor
|
||||
}
|
||||
|
||||
// #[instrument(level = "trace", err, skip(self))]
|
||||
// pub async fn close(&self) -> io::Result<()> {
|
||||
// self.inner.ws_meta.close().await.map_err(to_io).map(drop)
|
||||
// }
|
||||
#[cfg_attr(
|
||||
feature = "verbose-tracing",
|
||||
instrument(level = "trace", err, skip(self))
|
||||
)]
|
||||
pub async fn close(&self) -> io::Result<NetworkResult<()>> {
|
||||
let _ = self.inner.ws_meta.close().await.map_err(to_io)?;
|
||||
Ok(NetworkResult::value(()))
|
||||
}
|
||||
|
||||
#[cfg_attr(feature="verbose-tracing", instrument(level = "trace", err, skip(self, message), fields(network_result, message.len = message.len())))]
|
||||
pub async fn send(&self, message: Vec<u8>) -> io::Result<NetworkResult<()>> {
|
||||
|
Loading…
Reference in New Issue
Block a user