style(ipc): fix formatting
This commit is contained in:
parent
ad79f58dd4
commit
f22037beda
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use serde::{de::DeserializeOwned, Serialize};
|
use serde::{de::DeserializeOwned, Serialize};
|
||||||
use std::{path::Path};
|
use std::path::Path;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
|
@ -58,7 +58,10 @@ pub fn server<Event: Send + Sync + DeserializeOwned + Serialize>(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
pub fn client<Event: Serialize + DeserializeOwned>(id: &str, parent_dir: &Path) -> Result<impl IPCClient<Event>> {
|
pub fn client<Event: Serialize + DeserializeOwned>(
|
||||||
|
id: &str,
|
||||||
|
parent_dir: &Path,
|
||||||
|
) -> Result<impl IPCClient<Event>> {
|
||||||
let client = unix::UnixIPCClient::new(id, parent_dir)?;
|
let client = unix::UnixIPCClient::new(id, parent_dir)?;
|
||||||
Ok(client)
|
Ok(client)
|
||||||
}
|
}
|
||||||
|
@ -73,7 +76,10 @@ pub fn server<Event: Send + Sync + DeserializeOwned + Serialize>(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
pub fn client<Event: Serialize + DeserializeOwned>(id: &str, _: &Path) -> Result<impl IPCClient<Event>> {
|
pub fn client<Event: Serialize + DeserializeOwned>(
|
||||||
|
id: &str,
|
||||||
|
_: &Path,
|
||||||
|
) -> Result<impl IPCClient<Event>> {
|
||||||
let client = windows::WinIPCClient::new(id)?;
|
let client = windows::WinIPCClient::new(id)?;
|
||||||
Ok(client)
|
Ok(client)
|
||||||
}
|
}
|
||||||
|
@ -101,9 +107,7 @@ pub enum IPCClientError {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::{
|
use std::sync::mpsc::channel;
|
||||||
sync::{mpsc::channel},
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -119,7 +123,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn ipc_async_message() {
|
fn ipc_async_message() {
|
||||||
let server = server::<Event>("testespansoipcasync", &std::env::temp_dir()).unwrap();
|
let server = server::<Event>("testespansoipcasync", &std::env::temp_dir()).unwrap();
|
||||||
|
|
||||||
let client_handle = std::thread::spawn(move || {
|
let client_handle = std::thread::spawn(move || {
|
||||||
let mut client = client::<Event>("testespansoipcasync", &std::env::temp_dir()).unwrap();
|
let mut client = client::<Event>("testespansoipcasync", &std::env::temp_dir()).unwrap();
|
||||||
|
|
||||||
|
@ -143,7 +147,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn ipc_sync_message() {
|
fn ipc_sync_message() {
|
||||||
let server = server::<Event>("testespansoipcsync", &std::env::temp_dir()).unwrap();
|
let server = server::<Event>("testespansoipcsync", &std::env::temp_dir()).unwrap();
|
||||||
|
|
||||||
let client_handle = std::thread::spawn(move || {
|
let client_handle = std::thread::spawn(move || {
|
||||||
let mut client = client::<Event>("testespansoipcsync", &std::env::temp_dir()).unwrap();
|
let mut client = client::<Event>("testespansoipcsync", &std::env::temp_dir()).unwrap();
|
||||||
|
|
||||||
|
@ -167,9 +171,10 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn ipc_multiple_sync_with_delay_message() {
|
fn ipc_multiple_sync_with_delay_message() {
|
||||||
let server = server::<Event>("testespansoipcmultiplesync", &std::env::temp_dir()).unwrap();
|
let server = server::<Event>("testespansoipcmultiplesync", &std::env::temp_dir()).unwrap();
|
||||||
|
|
||||||
let client_handle = std::thread::spawn(move || {
|
let client_handle = std::thread::spawn(move || {
|
||||||
let mut client = client::<Event>("testespansoipcmultiplesync", &std::env::temp_dir()).unwrap();
|
let mut client =
|
||||||
|
client::<Event>("testespansoipcmultiplesync", &std::env::temp_dir()).unwrap();
|
||||||
|
|
||||||
let response = client.send_sync(Event::Sync("test".to_owned())).unwrap();
|
let response = client.send_sync(Event::Sync("test".to_owned())).unwrap();
|
||||||
|
|
||||||
|
@ -198,7 +203,7 @@ mod tests {
|
||||||
let server = server::<Event>("testespansoipcmultiple", &std::env::temp_dir()).unwrap();
|
let server = server::<Event>("testespansoipcmultiple", &std::env::temp_dir()).unwrap();
|
||||||
|
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
|
|
||||||
let client_handle = std::thread::spawn(move || {
|
let client_handle = std::thread::spawn(move || {
|
||||||
let mut client = client::<Event>("testespansoipcmultiple", &std::env::temp_dir()).unwrap();
|
let mut client = client::<Event>("testespansoipcmultiple", &std::env::temp_dir()).unwrap();
|
||||||
|
|
||||||
|
@ -234,10 +239,10 @@ mod tests {
|
||||||
client_handle2.join().unwrap();
|
client_handle2.join().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn ipc_sync_big_payload_message() {
|
fn ipc_sync_big_payload_message() {
|
||||||
let server = server::<Event>("testespansoipcsyncbig", &std::env::temp_dir()).unwrap();
|
let server = server::<Event>("testespansoipcsyncbig", &std::env::temp_dir()).unwrap();
|
||||||
|
|
||||||
let client_handle = std::thread::spawn(move || {
|
let client_handle = std::thread::spawn(move || {
|
||||||
let mut client = client::<Event>("testespansoipcsyncbig", &std::env::temp_dir()).unwrap();
|
let mut client = client::<Event>("testespansoipcsyncbig", &std::env::temp_dir()).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -17,14 +17,14 @@
|
||||||
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use crate::{EventHandlerResponse, IPCClientError, util::read_line};
|
use crate::{util::read_line, EventHandlerResponse, IPCClientError};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use serde::{de::DeserializeOwned, Serialize};
|
use serde::{de::DeserializeOwned, Serialize};
|
||||||
use std::{
|
use std::{
|
||||||
io::{Write},
|
io::Write,
|
||||||
os::unix::net::{UnixListener, UnixStream},
|
os::unix::net::{UnixListener, UnixStream},
|
||||||
path::{Path},
|
path::Path,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{EventHandler, IPCClient, IPCServer};
|
use crate::{EventHandler, IPCClient, IPCServer};
|
||||||
|
@ -143,4 +143,4 @@ impl<Event: Serialize + DeserializeOwned> IPCClient<Event> for UnixIPCClient {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,4 +44,4 @@ pub fn read_line<R: std::io::Read>(stream: R) -> Result<Option<String>> {
|
||||||
} else {
|
} else {
|
||||||
Ok(Some(String::from_utf8(buffer)?))
|
Ok(Some(String::from_utf8(buffer)?))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,16 +17,14 @@
|
||||||
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use crate::util::read_line;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use named_pipe::{ConnectingServer, PipeClient, PipeOptions};
|
use named_pipe::{ConnectingServer, PipeClient, PipeOptions};
|
||||||
use serde::{de::DeserializeOwned, Serialize};
|
use serde::{de::DeserializeOwned, Serialize};
|
||||||
use std::{io::{Write}};
|
use std::io::Write;
|
||||||
use crate::util::read_line;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{EventHandler, EventHandlerResponse, IPCClient, IPCClientError, IPCServer};
|
||||||
EventHandler, EventHandlerResponse, IPCClient, IPCClientError, IPCServer,
|
|
||||||
};
|
|
||||||
|
|
||||||
const DEFAULT_CLIENT_TIMEOUT: u32 = 2000;
|
const DEFAULT_CLIENT_TIMEOUT: u32 = 2000;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user