Skip to content

Commit

Permalink
fix: don't register file fd (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
NKID00 authored Aug 7, 2024
1 parent 2d653b2 commit 5118537
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion monoio/src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl File {
#[cfg(unix)]
pub fn from_std(std: StdFile) -> io::Result<File> {
Ok(File {
fd: SharedFd::new::<false>(std.into_raw_fd())?,
fd: SharedFd::new_without_register(std.into_raw_fd()),
})
}

Expand Down
15 changes: 15 additions & 0 deletions monoio/tests/fs_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,18 @@ fn assert_invalid_fd(fd: RawFd, base: std::fs::Metadata) {
}
}
}

#[monoio::test_all]
async fn file_from_std() {
let tempfile = tempfile();
let std_file = std::fs::OpenOptions::new()
.read(true)
.write(true)
.create(true)
.open(tempfile.path())
.unwrap();
let file = File::from_std(std_file).unwrap();
file.write_at(HELLO, 0).await.0.unwrap();
file.sync_all().await.unwrap();
read_hello(&file).await;
}

0 comments on commit 5118537

Please sign in to comment.