#[cfg_attr(target_family = "windows", path = "windows/mod.rs")]
#[cfg(target_family = "windows")]
pub mod windows;
use std::path::Path;
#[cfg(target_family = "windows")]
use crate::mio_uds_windows::UnixStream;
#[cfg(target_family = "unix")]
use tokio::net::UnixStream;
use tonic::transport::{Channel, Endpoint, Uri};
use tower::service_fn;
pub async fn socket_channel<P: AsRef<Path>>(path: P) -> Result<Channel, tonic::transport::Error> {
let p = path.as_ref().to_owned();
#[cfg(target_family = "unix")]
let res = Endpoint::from_static("http://[::]:50051")
.connect_with_connector(service_fn(move |_: Uri| {
UnixStream::connect(p.clone())
}))
.await;
#[cfg(target_family = "windows")]
let res = Endpoint::from_static("http://[::]:50051")
.connect_with_connector(service_fn(move |_: Uri| {
let path_copy = p.to_owned();
async move {
tokio::task::spawn_blocking(move || {
let stream = UnixStream::connect(path_copy)?;
windows::UnixStream::new(stream)
})
.await?
}
}))
.await;
res
}