ipc windows work
This commit is contained in:
		
							parent
							
								
									6f796db523
								
							
						
					
					
						commit
						05c4dacbe9
					
				
							
								
								
									
										22
									
								
								src/ipc.rs
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								src/ipc.rs
									
									
									
									
									
								
							| @ -5,10 +5,13 @@ use hbb_common::{ | ||||
|     futures::StreamExt as _, | ||||
|     futures_util::sink::SinkExt, | ||||
|     log, timeout, tokio, | ||||
|     tokio::io::{AsyncRead, AsyncWrite}, | ||||
|     tokio_util::codec::Framed, | ||||
|     ResultType, | ||||
| }; | ||||
| use parity_tokio_ipc::{Connection as Conn, Endpoint, Incoming, SecurityAttributes}; | ||||
| use parity_tokio_ipc::{ | ||||
|     Connection as Conn, ConnectionClient as ConnClient, Endpoint, Incoming, SecurityAttributes, | ||||
| }; | ||||
| use serde_derive::{Deserialize, Serialize}; | ||||
| use std::{collections::HashMap, net::SocketAddr}; | ||||
| #[cfg(not(windows))] | ||||
| @ -235,10 +238,10 @@ async fn handle(data: Data, stream: &mut Connection) { | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| pub async fn connect(ms_timeout: u64, postfix: &str) -> ResultType<Connection> { | ||||
| pub async fn connect(ms_timeout: u64, postfix: &str) -> ResultType<ConnectionTmpl<ConnClient>> { | ||||
|     let path = Config::ipc_path(postfix); | ||||
|     let client = timeout(ms_timeout, Endpoint::connect(&path)).await??; | ||||
|     Ok(Connection::new(client)) | ||||
|     Ok(ConnectionTmpl::new(client)) | ||||
| } | ||||
| 
 | ||||
| #[inline] | ||||
| @ -284,12 +287,17 @@ fn write_pid(postfix: &str) { | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| pub struct Connection { | ||||
|     inner: Framed<Conn, BytesCodec>, | ||||
| pub struct ConnectionTmpl<T> { | ||||
|     inner: Framed<T, BytesCodec>, | ||||
| } | ||||
| 
 | ||||
| impl Connection { | ||||
|     pub fn new(conn: Conn) -> Self { | ||||
| pub type Connection = ConnectionTmpl<Conn>; | ||||
| 
 | ||||
| impl<T> ConnectionTmpl<T> | ||||
| where | ||||
|     T: AsyncRead + AsyncWrite + std::marker::Unpin, | ||||
| { | ||||
|     pub fn new(conn: T) -> Self { | ||||
|         Self { | ||||
|             inner: Framed::new(conn, BytesCodec::new()), | ||||
|         } | ||||
|  | ||||
| @ -3,7 +3,6 @@ use crate::ipc; | ||||
| use hbb_common::{ | ||||
|     allow_err, bail, | ||||
|     config::{Config, APP_NAME}, | ||||
|     futures_util::stream::StreamExt, | ||||
|     log, sleep, timeout, tokio, | ||||
| }; | ||||
| use std::io::prelude::*; | ||||
| @ -652,7 +651,10 @@ pub fn get_active_username() -> String { | ||||
|         return "".to_owned(); | ||||
|     } | ||||
|     let sl = unsafe { std::slice::from_raw_parts(buff.as_ptr(), n as _) }; | ||||
|     String::from_utf16(sl).unwrap_or("??".to_owned()).trim_end_matches('\0').to_owned() | ||||
|     String::from_utf16(sl) | ||||
|         .unwrap_or("??".to_owned()) | ||||
|         .trim_end_matches('\0') | ||||
|         .to_owned() | ||||
| } | ||||
| 
 | ||||
| /* | ||||
| @ -1038,7 +1040,6 @@ pub fn get_installed_version() -> String { | ||||
|     "".to_owned() | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| pub fn create_shortcut(id: &str) -> ResultType<()> { | ||||
|     let exe = std::env::current_exe()?.to_str().unwrap_or("").to_owned(); | ||||
|     let shortcut = write_cmds( | ||||
|  | ||||
| @ -25,7 +25,7 @@ pub async fn listen( | ||||
|     interface: impl Interface, | ||||
|     ui_receiver: mpsc::UnboundedReceiver<Data>, | ||||
| ) -> ResultType<()> { | ||||
|     let mut listener = tcp::new_listener(format!("0.0.0.0:{}", port), true).await?; | ||||
|     let listener = tcp::new_listener(format!("0.0.0.0:{}", port), true).await?; | ||||
|     let addr = listener.local_addr()?; | ||||
|     log::info!("listening on port {:?}", addr); | ||||
|     let is_rdp = port == 0; | ||||
|  | ||||
| @ -66,7 +66,7 @@ async fn accept_connection_(server: ServerPtr, socket: Stream, secure: bool) -> | ||||
|     // even we drop socket, below still may fail if not use reuse_addr,
 | ||||
|     // there is TIME_WAIT before socket really released, so sometimes we
 | ||||
|     // see “Only one usage of each socket address is normally permitted” on windows sometimes,
 | ||||
|     let mut listener = new_listener(local_addr, true).await?; | ||||
|     let listener = new_listener(local_addr, true).await?; | ||||
|     log::info!("Server listening on: {}", &listener.local_addr()?); | ||||
|     if let Ok((stream, addr)) = timeout(CONNECT_TIMEOUT, listener.accept()).await? { | ||||
|         create_tcp_connection_(server, Stream::from(stream), addr, secure).await?; | ||||
|  | ||||
| @ -1,6 +1,4 @@ | ||||
| use crate::ipc::{self, new_listener, Connection, Data}; | ||||
| #[cfg(windows)] | ||||
| use hbb_common::futures_util::stream::StreamExt; | ||||
| use hbb_common::{ | ||||
|     allow_err, | ||||
|     config::{Config, ICON}, | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user