fix Windows pipe server

This commit is contained in:
Joseph Montanaro 2023-10-09 16:29:41 -07:00
parent 3f4efc5f8f
commit e0d919ed4a

View File

@ -1,11 +1,10 @@
use tokio::{ use tokio::net::windows::named_pipe::{
net::windows::named_pipe::{ NamedPipeServer,
NamedPipeServer, ServerOptions,
ServerOptions,
},
sync::oneshot,
}; };
use tauri::{AppHandle, Manager};
use windows::Win32:: { use windows::Win32:: {
Foundation::HANDLE, Foundation::HANDLE,
System::Pipes::GetNamedPipeClientProcessId, System::Pipes::GetNamedPipeClientProcessId,
@ -52,11 +51,11 @@ impl Server {
// create a new pipe instance to listen for the next client, and swap it in // create a new pipe instance to listen for the next client, and swap it in
let new_listener = ServerOptions::new().create(r"\\.\pipe\creddy-requests")?; let new_listener = ServerOptions::new().create(r"\\.\pipe\creddy-requests")?;
let mut stream = std::mem::replace(&mut self.listener, new_listener); let stream = std::mem::replace(&mut self.listener, new_listener);
let new_handle = self.app_handle.app_handle(); let new_handle = self.app_handle.app_handle();
let client_pid = get_client_pid(&stream)?; let client_pid = get_client_pid(&stream)?;
rt::spawn(async move { rt::spawn(async move {
super::handle(stream, app_handle) super::handle(stream, new_handle, client_pid)
.await .await
.error_print_prefix("Error responding to request: "); .error_print_prefix("Error responding to request: ");
}); });
@ -71,5 +70,5 @@ fn get_client_pid(pipe: &NamedPipeServer) -> Result<u32, ClientInfoError> {
let mut pid = 0u32; let mut pid = 0u32;
let handle = HANDLE(raw_handle as _); let handle = HANDLE(raw_handle as _);
unsafe { GetNamedPipeClientProcessId(handle, &mut pid as *mut u32)? }; unsafe { GetNamedPipeClientProcessId(handle, &mut pid as *mut u32)? };
pid Ok(pid)
} }