Compile UnixStream support only on unix systems

This commit is contained in:
AsamK 2025-07-12 11:41:52 +02:00
parent dbdff83132
commit 3d4070a139
4 changed files with 25 additions and 15 deletions

View file

@ -15,6 +15,7 @@ pub struct Cli {
pub json_rpc_tcp: Option<Option<SocketAddr>>, pub json_rpc_tcp: Option<Option<SocketAddr>>,
/// UNIX socket address and port of signal-cli daemon /// UNIX socket address and port of signal-cli daemon
#[cfg(unix)]
#[arg(long, conflicts_with = "json_rpc_tcp")] #[arg(long, conflicts_with = "json_rpc_tcp")]
pub json_rpc_socket: Option<Option<OsString>>, pub json_rpc_socket: Option<Option<OsString>>,

View file

@ -410,6 +410,7 @@ pub async fn connect_tcp(
Ok(ClientBuilder::default().build_with_tokio(sender, receiver)) Ok(ClientBuilder::default().build_with_tokio(sender, receiver))
} }
#[cfg(unix)]
pub async fn connect_unix( pub async fn connect_unix(
socket_path: impl AsRef<Path>, socket_path: impl AsRef<Path>,
) -> Result<impl SubscriptionClientT, std::io::Error> { ) -> Result<impl SubscriptionClientT, std::io::Error> {

View file

@ -482,23 +482,30 @@ async fn connect(cli: Cli) -> Result<Value, RpcError> {
handle_command(cli, client).await handle_command(cli, client).await
} else { } else {
let socket_path = cli #[cfg(windows)]
.json_rpc_socket {
.clone() Err(RpcError::Custom("Invalid socket".into()))
.unwrap_or(None) }
.or_else(|| { #[cfg(unix)]
std::env::var_os("XDG_RUNTIME_DIR").map(|runtime_dir| { {
PathBuf::from(runtime_dir) let socket_path = cli
.join(DEFAULT_SOCKET_SUFFIX) .json_rpc_socket
.into() .clone()
.unwrap_or(None)
.or_else(|| {
std::env::var_os("XDG_RUNTIME_DIR").map(|runtime_dir| {
PathBuf::from(runtime_dir)
.join(DEFAULT_SOCKET_SUFFIX)
.into()
})
}) })
}) .unwrap_or_else(|| ("/run".to_owned() + DEFAULT_SOCKET_SUFFIX).into());
.unwrap_or_else(|| ("/run".to_owned() + DEFAULT_SOCKET_SUFFIX).into()); let client = jsonrpc::connect_unix(socket_path)
let client = jsonrpc::connect_unix(socket_path) .await
.await .map_err(|e| RpcError::Custom(format!("Failed to connect to socket: {e}")))?;
.map_err(|e| RpcError::Custom(format!("Failed to connect to socket: {e}")))?;
handle_command(cli, client).await handle_command(cli, client).await
}
} }
} }

View file

@ -2,6 +2,7 @@ use futures_util::{stream::StreamExt, Sink, SinkExt, Stream};
use jsonrpsee::core::client::{ReceivedMessage, TransportReceiverT, TransportSenderT}; use jsonrpsee::core::client::{ReceivedMessage, TransportReceiverT, TransportSenderT};
use thiserror::Error; use thiserror::Error;
#[cfg(unix)]
pub mod ipc; pub mod ipc;
mod stream_codec; mod stream_codec;
pub mod tcp; pub mod tcp;