fix tokio

This commit is contained in:
John Smith
2022-06-29 10:13:49 -04:00
parent d3f872eb1f
commit 018d7da429
20 changed files with 115 additions and 54 deletions

View File

@@ -561,7 +561,7 @@ impl Network {
// Drop the stop
drop(inner.stop_source.take());
}
debug!("stopping {} low level network tasks", unord.len(),);
debug!("stopping {} low level network tasks", unord.len());
// Wait for everything to stop
while unord.next().await.is_some() {}

View File

@@ -208,6 +208,7 @@ impl Network {
if #[cfg(feature="rt-async-std")] {
let listener = TcpListener::from(std_listener);
} else if #[cfg(feature="rt-tokio")] {
std_listener.set_nonblocking(true).expect("failed to set nonblocking");
let listener = TcpListener::from_std(std_listener).map_err(map_to_string)?;
}
}

View File

@@ -23,7 +23,7 @@ impl Network {
// Run thread task to process stream of messages
let this = self.clone();
let jh = spawn_with_local_set(async move {
let jh = spawn(async move {
trace!("UDP listener task spawned");
// Collect all our protocol handlers into a vector
@@ -49,7 +49,7 @@ impl Network {
for ph in protocol_handlers {
let network_manager = network_manager.clone();
let stop_token = stop_token.clone();
let jh = intf::spawn_local(async move {
let ph_future = async move {
let mut data = vec![0u8; 65536];
loop {
@@ -84,26 +84,18 @@ impl Network {
}
}
}
});
};
protocol_handlers_unordered.push(jh);
protocol_handlers_unordered.push(ph_future);
}
// Now we wait for join handles to exit,
// if any error out it indicates an error needing
// us to completely restart the network
loop {
match protocol_handlers_unordered.next().await {
Some(v) => {
// true = stopped, false = errored
if !v {
// If any protocol handler fails, our socket died and we need to restart the network
this.inner.lock().network_needs_restart = true;
}
}
None => {
// All protocol handlers exited
break;
}
while let Some(v) = protocol_handlers_unordered.next().await {
// true = stopped, false = errored
if !v {
// If any protocol handler fails, our socket died and we need to restart the network
this.inner.lock().network_needs_restart = true;
}
}
@@ -138,6 +130,7 @@ impl Network {
if #[cfg(feature="rt-async-std")] {
let udp_socket = UdpSocket::from(std_udp_socket);
} else if #[cfg(feature="rt-tokio")] {
std_udp_socket.set_nonblocking(true).expect("failed to set nonblocking");
let udp_socket = UdpSocket::from_std(std_udp_socket).map_err(map_to_string)?;
}
}
@@ -158,6 +151,7 @@ impl Network {
if #[cfg(feature="rt-async-std")] {
let udp_socket = UdpSocket::from(std_udp_socket);
} else if #[cfg(feature="rt-tokio")] {
std_udp_socket.set_nonblocking(true).expect("failed to set nonblocking");
let udp_socket = UdpSocket::from_std(std_udp_socket).map_err(map_to_string)?;
}
}
@@ -184,6 +178,7 @@ impl Network {
if #[cfg(feature="rt-async-std")] {
let udp_socket = UdpSocket::from(std_udp_socket);
} else if #[cfg(feature="rt-tokio")] {
std_udp_socket.set_nonblocking(true).expect("failed to set nonblocking");
let udp_socket = UdpSocket::from_std(std_udp_socket).map_err(map_to_string)?;
}
}