diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index e074fa190..9b512694e 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -134,9 +134,6 @@ features = [ "Win32_Security_Authorization", ] -[target.'cfg(windows)'.dev-dependencies.ntapi] -version = "0.3.6" - [dev-dependencies] tokio-test = { version = "0.4.0", path = "../tokio-test" } tokio-stream = { version = "0.1", path = "../tokio-stream" } diff --git a/tokio/tests/net_named_pipe.rs b/tokio/tests/net_named_pipe.rs index 02c8a0919..02eda48e5 100644 --- a/tokio/tests/net_named_pipe.rs +++ b/tokio/tests/net_named_pipe.rs @@ -2,13 +2,11 @@ #![cfg(all(windows))] use std::io; -use std::mem; -use std::os::windows::io::AsRawHandle; use std::time::Duration; use tokio::io::{AsyncReadExt, AsyncWriteExt}; use tokio::net::windows::named_pipe::{ClientOptions, PipeMode, ServerOptions}; use tokio::time; -use windows_sys::Win32::Foundation::{ERROR_NO_DATA, ERROR_PIPE_BUSY, NO_ERROR, UNICODE_STRING}; +use windows_sys::Win32::Foundation::{ERROR_NO_DATA, ERROR_PIPE_BUSY}; #[tokio::test] async fn test_named_pipe_client_drop() -> io::Result<()> { @@ -16,8 +14,6 @@ async fn test_named_pipe_client_drop() -> io::Result<()> { let mut server = ServerOptions::new().create(PIPE_NAME)?; - assert_eq!(num_instances("test-named-pipe-client-drop")?, 1); - let client = ClientOptions::new().open(PIPE_NAME)?; server.connect().await?; @@ -401,53 +397,3 @@ async fn test_named_pipe_access() -> io::Result<()> { } Ok(()) } - -fn num_instances(pipe_name: impl AsRef) -> io::Result { - use ntapi::ntioapi; - - let mut name = pipe_name.as_ref().encode_utf16().collect::>(); - let mut name = UNICODE_STRING { - Length: (name.len() * mem::size_of::()) as u16, - MaximumLength: (name.len() * mem::size_of::()) as u16, - Buffer: name.as_mut_ptr(), - }; - let root = std::fs::File::open(r"\\.\Pipe\")?; - let mut io_status_block = unsafe { mem::zeroed() }; - let mut file_directory_information = [0_u8; 1024]; - - let status = unsafe { - ntioapi::NtQueryDirectoryFile( - root.as_raw_handle().cast(), - std::ptr::null_mut(), - None, - std::ptr::null_mut(), - &mut io_status_block, - &mut file_directory_information as *mut _ as *mut _, - 1024, - ntioapi::FileDirectoryInformation, - 0, - &mut name as *mut _ as _, - 0, - ) - }; - - if status as u32 != NO_ERROR { - return Err(io::Error::last_os_error()); - } - - let info = unsafe { - mem::transmute::<_, &ntioapi::FILE_DIRECTORY_INFORMATION>(&file_directory_information) - }; - let raw_name = unsafe { - std::slice::from_raw_parts( - info.FileName.as_ptr(), - info.FileNameLength as usize / mem::size_of::(), - ) - }; - let name = String::from_utf16(raw_name).unwrap(); - let num_instances = unsafe { *info.EndOfFile.QuadPart() }; - - assert_eq!(name, pipe_name.as_ref()); - - Ok(num_instances as u32) -}