Skip to content

Commit

Permalink
Fix socket status reading (#575)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinc authored Feb 11, 2024
1 parent 69ab9eb commit c3cf72b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/usr/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,8 @@ pub fn main(args: &[&str]) -> Result<(), ExitCode> {
syscall::sleep(0.01);
if connected {
let mut data = vec![0; 1]; // 1 byte status read
let status = SocketStatus::MayRecv as usize;
let may_recv = data[0].get_bit(status);
match syscall::read(handle, &mut data) {
Some(1) if !may_recv => break, // recv closed
Some(1) if is_closed(data[0]) => break,
_ => continue,
}
}
Expand All @@ -148,6 +146,10 @@ pub fn main(args: &[&str]) -> Result<(), ExitCode> {
}
}

fn is_closed(status: u8) -> bool {
!status.get_bit(SocketStatus::MayRecv as usize)
}

fn help() {
let csi_option = Style::color("LightCyan");
let csi_title = Style::color("Yellow");
Expand Down

0 comments on commit c3cf72b

Please sign in to comment.