Skip to content

Commit

Permalink
pencil: fix wrongly set std io nonblocking
Browse files Browse the repository at this point in the history
this test was setting std input to nonblocking mode, and would affect
std out print function. so we have to use a real file that is safe to
set to nonblocking
  • Loading branch information
Xudong-Huang committed Dec 23, 2024
1 parent d3d4042 commit 7843462
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/io/sys/unix/co_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,23 @@ mod tests {
#[test]
fn compile_co_io() {
#[derive(Debug)]
struct Fd;
struct Fd {
file: std::net::UdpSocket,
}

impl Fd {
fn new() -> Self {
Fd {
// this would call set_nonblocking for the fd
// so we need to open a real fd here
file: std::net::UdpSocket::bind(("127.0.0.1", 9765)).unwrap(),
}
}
}

impl AsRawFd for Fd {
fn as_raw_fd(&self) -> RawFd {
0
self.file.as_raw_fd()
}
}

Expand All @@ -283,7 +295,7 @@ mod tests {
}
}

let a = Fd;
let a = Fd::new();
let mut io = CoIo::new(a).unwrap();
let mut buf = [0u8; 100];
io.read_exact(&mut buf).unwrap();
Expand Down

0 comments on commit 7843462

Please sign in to comment.