Skip to content

Commit

Permalink
chore: remove ntapi dev-dependency (#5642)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darksonn committed Apr 21, 2023
1 parent b9868b2 commit 77e3911
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 58 deletions.
3 changes: 0 additions & 3 deletions tokio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
56 changes: 1 addition & 55 deletions tokio/tests/net_named_pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@
#![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<()> {
const PIPE_NAME: &str = r"\\.\pipe\test-named-pipe-client-drop";

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?;
Expand Down Expand Up @@ -401,53 +397,3 @@ async fn test_named_pipe_access() -> io::Result<()> {
}
Ok(())
}

fn num_instances(pipe_name: impl AsRef<str>) -> io::Result<u32> {
use ntapi::ntioapi;

let mut name = pipe_name.as_ref().encode_utf16().collect::<Vec<_>>();
let mut name = UNICODE_STRING {
Length: (name.len() * mem::size_of::<u16>()) as u16,
MaximumLength: (name.len() * mem::size_of::<u16>()) 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::<u16>(),
)
};
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)
}

0 comments on commit 77e3911

Please sign in to comment.