diff options
author | haturau <135221985+haturatu@users.noreply.github.com> | 2024-11-20 01:20:47 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-20 01:20:47 +0900 |
commit | 85719a67e59c7aa45bead26e4942d7df8b1b42d4 (patch) | |
tree | face0aecaac53e93ce2f23b53c48859bcf1a36ec /tests/specs/node/child_process_extra_pipes/test-pipe/src/main.rs | |
parent | 67697bc2e4a62a9670699fd18ad0dd8efc5bd955 (diff) | |
parent | 186b52731c6bb326c4d32905c5e732d082e83465 (diff) |
Merge branch 'denoland:main' into main
Diffstat (limited to 'tests/specs/node/child_process_extra_pipes/test-pipe/src/main.rs')
-rw-r--r-- | tests/specs/node/child_process_extra_pipes/test-pipe/src/main.rs | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/tests/specs/node/child_process_extra_pipes/test-pipe/src/main.rs b/tests/specs/node/child_process_extra_pipes/test-pipe/src/main.rs index 192f82731..acc034830 100644 --- a/tests/specs/node/child_process_extra_pipes/test-pipe/src/main.rs +++ b/tests/specs/node/child_process_extra_pipes/test-pipe/src/main.rs @@ -1,12 +1,31 @@ +use std::fs::File; use std::io::prelude::*; use std::os::fd::FromRawFd; -use std::os::unix::net::UnixStream; fn main() { #[cfg(unix)] { - let mut stream = unsafe { UnixStream::from_raw_fd(4) }; + let mut pipe = unsafe { File::from_raw_fd(4) }; - stream.write_all(b"hello world\n").unwrap(); + let mut read = 0; + let mut buf = [0u8; 1024]; + loop { + if read > 4 { + assert_eq!(&buf[..5], b"start"); + break; + } + match pipe.read(&mut buf) { + Ok(n) => { + read += n; + } + Ok(0) => { + return; + } + Err(e) => { + eprintln!("GOT ERROR: {e:?}"); + } + } + } + pipe.write_all(b"hello world").unwrap(); } } |