Skip to content

Commit

Permalink
Fix write loop
Browse files Browse the repository at this point in the history
  • Loading branch information
vinc committed Jul 9, 2023
1 parent 99c640c commit 9e5b080
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/sys/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ impl FileIO for TcpSocket {
fn write(&mut self, buf: &[u8]) -> Result<usize, ()> {
let timeout = 5.0;
let started = sys::clock::realtime();
let mut sent = false;
if let Some((ref mut iface, ref mut device)) = *sys::net::NET.lock() {
let mut sockets = SOCKETS.lock();
loop {
Expand All @@ -389,11 +390,14 @@ impl FileIO for TcpSocket {
iface.poll(time(), device, &mut sockets);
let socket = sockets.get_mut::<tcp::Socket>(self.handle);

if sent {
break;
}
if socket.can_send() {
if socket.send_slice(buf.as_ref()).is_err() {
return Err(());
}
break;
sent = true; // Break after next poll
}

if let Some(duration) = iface.poll_delay(time(), &sockets) {
Expand Down

0 comments on commit 9e5b080

Please sign in to comment.