fix blocked issue

This commit is contained in:
John Smith 2023-07-03 11:38:40 -04:00
parent 7d4d83b6ac
commit b7e531f35b
7 changed files with 22 additions and 10 deletions

View File

@ -468,7 +468,7 @@ impl PlatformSupportApple {
) { ) {
Ok(v) => v, Ok(v) => v,
Err(e) => { Err(e) => {
log_net!(error "{}", e); log_net!(error "failed to get address flags: {}", e);
continue; continue;
} }
}; };

View File

@ -704,7 +704,7 @@ impl Network {
} }
} }
// Do TCPv4 + WSv4 in series because they may use the same connection 5-tuple // Do TCPv4. Possibly do WSv4 if it is on a different port
if protocol_config.family_global.contains(AddressType::IPV4) { if protocol_config.family_global.contains(AddressType::IPV4) {
if protocol_config.inbound.contains(ProtocolType::TCP) { if protocol_config.inbound.contains(ProtocolType::TCP) {
futures.push( futures.push(
@ -747,7 +747,7 @@ impl Network {
} }
} }
// Do TCPv6 + WSv6 in series because they may use the same connection 5-tuple // Do TCPv6. Possibly do WSv6 if it is on a different port
if protocol_config.family_global.contains(AddressType::IPV6) { if protocol_config.family_global.contains(AddressType::IPV6) {
if protocol_config.inbound.contains(ProtocolType::TCP) { if protocol_config.inbound.contains(ProtocolType::TCP) {
futures.push( futures.push(

View File

@ -95,6 +95,18 @@ pub fn new_bound_first_udp_socket(local_address: SocketAddr) -> io::Result<Socke
Ok(socket) Ok(socket)
} }
#[instrument(level = "trace", ret)]
pub fn new_unbound_tcp_socket(domain: Domain) -> io::Result<Socket> {
let socket = Socket::new(domain, Type::STREAM, Some(Protocol::TCP))?;
if let Err(e) = socket.set_nodelay(true) {
log_net!(error "Couldn't set TCP nodelay: {}", e);
}
if domain == Domain::IPV6 {
socket.set_only_v6(true)?;
}
Ok(socket)
}
#[instrument(level = "trace", ret)] #[instrument(level = "trace", ret)]
pub fn new_unbound_shared_tcp_socket(domain: Domain) -> io::Result<Socket> { pub fn new_unbound_shared_tcp_socket(domain: Domain) -> io::Result<Socket> {
let socket = Socket::new(domain, Type::STREAM, Some(Protocol::TCP))?; let socket = Socket::new(domain, Type::STREAM, Some(Protocol::TCP))?;

View File

@ -162,7 +162,7 @@ impl RawTcpProtocolHandler {
// Make a shared socket // Make a shared socket
let socket = match local_address { let socket = match local_address {
Some(a) => new_bound_shared_tcp_socket(a)?, Some(a) => new_bound_shared_tcp_socket(a)?,
None => new_unbound_shared_tcp_socket(socket2::Domain::for_address(socket_addr))?, None => new_unbound_tcp_socket(socket2::Domain::for_address(socket_addr))?,
}; };
// Non-blocking connect to remote address // Non-blocking connect to remote address

View File

@ -246,9 +246,7 @@ impl WebsocketProtocolHandler {
// Make a shared socket // Make a shared socket
let socket = match local_address { let socket = match local_address {
Some(a) => new_bound_shared_tcp_socket(a)?, Some(a) => new_bound_shared_tcp_socket(a)?,
None => { None => new_unbound_tcp_socket(socket2::Domain::for_address(remote_socket_addr))?,
new_unbound_shared_tcp_socket(socket2::Domain::for_address(remote_socket_addr))?
}
}; };
// Non-blocking connect to remote address // Non-blocking connect to remote address

View File

@ -323,7 +323,7 @@ impl NetworkConnection {
} }
Err(e) => { Err(e) => {
// Connection unable to receive, closed // Connection unable to receive, closed
log_net!(error e); log_net!(error "connection unable to receive: {}", e);
RecvLoopAction::Finish RecvLoopAction::Finish
} }
} }

View File

@ -31,7 +31,8 @@ impl<T> IoNetworkResultExt<T> for io::Result<T> {
#[cfg(feature = "io_error_more")] #[cfg(feature = "io_error_more")]
Err(e) => match e.kind() { Err(e) => match e.kind() {
io::ErrorKind::TimedOut => Ok(NetworkResult::Timeout), io::ErrorKind::TimedOut => Ok(NetworkResult::Timeout),
io::ErrorKind::ConnectionAborted io::ErrorKind::UnexpectedEof
| io::ErrorKind::ConnectionAborted
| io::ErrorKind::ConnectionRefused | io::ErrorKind::ConnectionRefused
| io::ErrorKind::ConnectionReset | io::ErrorKind::ConnectionReset
| io::ErrorKind::HostUnreachable | io::ErrorKind::HostUnreachable
@ -49,7 +50,8 @@ impl<T> IoNetworkResultExt<T> for io::Result<T> {
} }
match e.kind() { match e.kind() {
io::ErrorKind::TimedOut => Ok(NetworkResult::Timeout), io::ErrorKind::TimedOut => Ok(NetworkResult::Timeout),
io::ErrorKind::ConnectionAborted io::ErrorKind::UnexpectedEof
| io::ErrorKind::ConnectionAborted
| io::ErrorKind::ConnectionRefused | io::ErrorKind::ConnectionRefused
| io::ErrorKind::ConnectionReset => Ok(NetworkResult::NoConnection(e)), | io::ErrorKind::ConnectionReset => Ok(NetworkResult::NoConnection(e)),
io::ErrorKind::AddrNotAvailable => Ok(NetworkResult::AlreadyExists(e)), io::ErrorKind::AddrNotAvailable => Ok(NetworkResult::AlreadyExists(e)),