-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
268 additions
and
53 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,6 @@ impl Run { | |
} | ||
} | ||
|
||
Supervisor::new(pid_file).start().await | ||
Supervisor::new(pid_file).await?.start().await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,46 @@ | ||
use tokio::sync::Mutex; | ||
use crate::ipc::{fs_name, IpcMessage}; | ||
use crate::{env, ipc, Result}; | ||
use interprocess::local_socket::tokio::{RecvHalf, SendHalf}; | ||
use interprocess::local_socket::traits::tokio::Stream; | ||
use interprocess::local_socket::{GenericFilePath, ToFsName}; | ||
use tokio::io::{AsyncWriteExt, BufReader}; | ||
use uuid::Uuid; | ||
|
||
pub struct IpcClient { | ||
id: String, | ||
recv: BufReader<RecvHalf>, | ||
send: Mutex<SendHalf>, | ||
} | ||
|
||
impl IpcClient { | ||
pub async fn connect() -> Result<Self> { | ||
// ensure nobody else can connect to the IPC server at the same time | ||
let _fslock = xx::fslock::get(&*env::IPC_SOCK_MAIN, false)?; | ||
let conn = | ||
interprocess::local_socket::tokio::Stream::connect(fs_name(&env::IPC_SOCK_MAIN)?) | ||
.await?; | ||
debug!("Connected to IPC main"); | ||
let (recv, send) = conn.split(); | ||
let recv = BufReader::new(recv); | ||
let id = Uuid::new_v4().to_string(); | ||
let client = IpcClient { id, recv, send: Mutex::new(send) }; | ||
client.send(IpcMessage::Connect(client.id.clone())).await?; | ||
Ok(client) | ||
} | ||
|
||
pub async fn send(&self, msg: IpcMessage) -> Result<()> { | ||
let mut msg = if *env::IPC_JSON { | ||
serde_json::to_vec(&msg)? | ||
} else { | ||
rmp_serde::to_vec(&msg)? | ||
}; | ||
// if msg.contains(&b'\n') { | ||
// panic!("IPC message contains newline"); | ||
// } | ||
msg.push(0); | ||
let mut send = self.send.lock().await; | ||
send.write_all(&msg).await?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,16 @@ | ||
use std::path::Path; | ||
use interprocess::local_socket::{GenericFilePath, Name, ToFsName}; | ||
|
||
pub(crate) mod client; | ||
pub(crate) mod server; | ||
|
||
#[derive(Debug, serde::Serialize, serde::Deserialize, strum::Display)] | ||
pub enum IpcMessage { | ||
Connect(String), | ||
Response(String), | ||
} | ||
|
||
pub fn fs_name(path: &Path) -> eyre::Result<Name> { | ||
let fs_name = path.to_fs_name::<GenericFilePath>()?; | ||
Ok(fs_name) | ||
} |
Oops, something went wrong.