From 5118537d41105732bb75c0bdd2c5527b7387b5aa Mon Sep 17 00:00:00 2001 From: NKID00 Date: Wed, 7 Aug 2024 16:05:05 +0800 Subject: [PATCH] fix: don't register file fd (#277) --- monoio/src/fs/file.rs | 2 +- monoio/tests/fs_file.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/monoio/src/fs/file.rs b/monoio/src/fs/file.rs index 05366750..70b1ab3f 100644 --- a/monoio/src/fs/file.rs +++ b/monoio/src/fs/file.rs @@ -142,7 +142,7 @@ impl File { #[cfg(unix)] pub fn from_std(std: StdFile) -> io::Result { Ok(File { - fd: SharedFd::new::(std.into_raw_fd())?, + fd: SharedFd::new_without_register(std.into_raw_fd()), }) } diff --git a/monoio/tests/fs_file.rs b/monoio/tests/fs_file.rs index 13fe492e..6e24e9a2 100644 --- a/monoio/tests/fs_file.rs +++ b/monoio/tests/fs_file.rs @@ -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; +}