diff --git a/monoio/src/fs/file/windows.rs b/monoio/src/fs/file/windows.rs index 59e33ae7..f3f4b20e 100644 --- a/monoio/src/fs/file/windows.rs +++ b/monoio/src/fs/file/windows.rs @@ -12,7 +12,7 @@ use windows_sys::Win32::Networking::WinSock::WSABUF; use super::File; use crate::{ buf::{IoBuf, IoBufMut, IoVecBuf, IoVecBufMut}, - driver::{op::Op, shared_fd::SharedFd}, + driver::shared_fd::SharedFd, }; impl AsRawHandle for File { @@ -45,13 +45,12 @@ mod blocking { let raw_bufs = buf_vec.write_wsabuf_ptr(); let len = buf_vec.write_wsabuf_len(); - // Safely wrap the raw pointers into a Vec, but prevent automatic cleanup with ManuallyDrop - let wasbufs = ManuallyDrop::new(unsafe { Vec::from_raw_parts(raw_bufs, len, len) }); + let wsabufs = unsafe { slice::from_raw_parts(raw_bufs, len, len) }; let mut total_bytes_read = 0; // Iterate through each WSABUF structure and read data into it - for wsabuf in wasbufs.iter() { + for wsabuf in wsabufs.iter() { // Safely create a Vec from the WSABUF pointer, then pass it to the read function let (res, _) = read( fd.clone(), @@ -83,7 +82,7 @@ mod blocking { } /// The `writev` implement on windows - /// + /// /// Due to windows does not have syscall like `writev`, so we need to simulate it by ourself. /// /// This function is just to write each buffer into file by calling the `write` function. @@ -95,8 +94,7 @@ mod blocking { let raw_bufs = buf_vec.read_wsabuf_ptr() as *mut WSABUF; let len = buf_vec.read_wsabuf_len(); - // Safely wrap the raw pointers into a Vec, but prevent automatic cleanup with ManuallyDrop - let wsabufs = ManuallyDrop::new(unsafe { Vec::from_raw_parts(raw_bufs, len, len) }); + let wsabufs = unsafe { slice::from_raw_parts(raw_bufs, len, len) }; let mut total_bytes_write = 0; // Iterate through each WSABUF structure and write data from it @@ -162,16 +160,12 @@ mod asyncified { let fd = fd.as_raw_handle() as _; let res = asyncify(move || { - // Safely wrap the raw pointers into a Vec, but prevent automatic cleanup with - // ManuallyDrop - let wasbufs = ManuallyDrop::new(unsafe { - Vec::from_raw_parts(raw_bufs as *mut WSABUF, len, len) - }); + let wsabufs = unsafe { slice::from_raw_parts(raw_bufs as *mut WSABUF, len) }; let mut total_bytes_read = 0; // Iterate through each WSABUF structure and read data into it - for wsabuf in wasbufs.iter() { + for wsabuf in wsabufs.iter() { let res = read::read(fd, wsabuf.buf, wsabuf.len as usize); // Handle the result of the read operation @@ -203,7 +197,7 @@ mod asyncified { } /// The `writev` implement on windows - /// + /// /// Due to windows does not have syscall like `writev`, so we need to simulate it by ourself. /// /// This function is just to write each buffer into file by calling the `write` function. @@ -218,11 +212,7 @@ mod asyncified { let fd = fd.as_raw_handle() as _; let res = asyncify(move || { - // Safely wrap the raw pointers into a Vec, but prevent automatic cleanup with - // ManuallyDrop - let wsabufs = ManuallyDrop::new(unsafe { - Vec::from_raw_parts(raw_bufs as *mut WSABUF, len, len) - }); + let wsabufs = unsafe { slice::from_raw_parts(raw_bufs as *mut WSABUF, len, len) }; let mut total_bytes_write = 0; diff --git a/monoio/src/fs/mod.rs b/monoio/src/fs/mod.rs index 695a1b83..54a6b96e 100644 --- a/monoio/src/fs/mod.rs +++ b/monoio/src/fs/mod.rs @@ -36,7 +36,7 @@ pub use file_type::FileType; #[cfg(unix)] mod permissions; #[cfg(windows)] -use std::os::windows::io::{AsRawHandle, FromRawHandle, IntoRawHandle}; +use std::os::windows::io::{AsRawHandle, FromRawHandle}; #[cfg(unix)] pub use permissions::Permissions;