mirror of https://github.com/wayvr-org/wayvr.git
swich tokio to smol
This commit is contained in:
parent
2e7a528857
commit
867c343c9b
|
|
@ -6514,6 +6514,7 @@ dependencies = [
|
||||||
"async-channel",
|
"async-channel",
|
||||||
"async-io",
|
"async-io",
|
||||||
"bytes",
|
"bytes",
|
||||||
|
"interprocess",
|
||||||
"log",
|
"log",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ anyhow.workspace = true
|
||||||
async-channel.workspace = true
|
async-channel.workspace = true
|
||||||
async-io.workspace = true
|
async-io.workspace = true
|
||||||
bytes.workspace = true
|
bytes.workspace = true
|
||||||
|
interprocess.workspace = true
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
smallvec.workspace = true
|
smallvec.workspace = true
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
use bytes::BufMut;
|
use bytes::BufMut;
|
||||||
|
use interprocess::local_socket::{self, ToNsName};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use smol::io::AsyncReadExt;
|
use smol::io::AsyncReadExt;
|
||||||
use smol::io::AsyncWriteExt;
|
use smol::io::AsyncWriteExt;
|
||||||
use smol::lock::Mutex;
|
use smol::lock::Mutex;
|
||||||
use smol::net::unix::UnixStream;
|
use std::os::unix::net::UnixStream as StdUnixStream;
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
@ -65,6 +66,24 @@ pub type WayVRClientWeak = Weak<Mutex<WayVRClient>>;
|
||||||
type ReceiverMutex = Arc<Mutex<smol::net::unix::UnixStream>>;
|
type ReceiverMutex = Arc<Mutex<smol::net::unix::UnixStream>>;
|
||||||
type SenderMutex = Arc<Mutex<smol::net::unix::UnixStream>>;
|
type SenderMutex = Arc<Mutex<smol::net::unix::UnixStream>>;
|
||||||
|
|
||||||
|
fn interprocess_stream_to_async(
|
||||||
|
stream: local_socket::Stream,
|
||||||
|
) -> anyhow::Result<smol::net::unix::UnixStream> {
|
||||||
|
use std::os::unix::io::OwnedFd;
|
||||||
|
|
||||||
|
let uds_stream: interprocess::os::unix::uds_local_socket::Stream = match stream {
|
||||||
|
local_socket::Stream::UdSocket(s) => s,
|
||||||
|
#[allow(unreachable_patterns)]
|
||||||
|
_ => anyhow::bail!("Unsupported socket type"),
|
||||||
|
};
|
||||||
|
|
||||||
|
let owned_fd: OwnedFd = uds_stream.into();
|
||||||
|
let std_stream = StdUnixStream::from(owned_fd);
|
||||||
|
|
||||||
|
smol::net::unix::UnixStream::try_from(std_stream)
|
||||||
|
.map_err(|e| anyhow::anyhow!("Failed to wrap socket for async I/O: {}", e))
|
||||||
|
}
|
||||||
|
|
||||||
async fn client_runner(client: WayVRClientMutex) -> anyhow::Result<()> {
|
async fn client_runner(client: WayVRClientMutex) -> anyhow::Result<()> {
|
||||||
loop {
|
loop {
|
||||||
WayVRClient::tick(client.clone()).await?;
|
WayVRClient::tick(client.clone()).await?;
|
||||||
|
|
@ -118,14 +137,17 @@ impl WayVRClient {
|
||||||
pub async fn new(client_name: &str) -> anyhow::Result<WayVRClientMutex> {
|
pub async fn new(client_name: &str) -> anyhow::Result<WayVRClientMutex> {
|
||||||
let printname = "/tmp/wayvr_ipc.sock";
|
let printname = "/tmp/wayvr_ipc.sock";
|
||||||
|
|
||||||
let stream = match UnixStream::connect(printname).await {
|
let name = printname
|
||||||
Ok(c) => c,
|
.to_ns_name::<local_socket::GenericNamespaced>()
|
||||||
Err(e) => {
|
.map_err(|e| anyhow::anyhow!("Failed to create socket name: {}", e))?;
|
||||||
anyhow::bail!("Failed to connect to the WayVR IPC: {}", e)
|
let opts = local_socket::ConnectOptions::new().name(name);
|
||||||
}
|
let ip_stream = opts
|
||||||
};
|
.connect_sync()
|
||||||
let receiver = Arc::new(Mutex::new(stream.clone()));
|
.map_err(|e| anyhow::anyhow!("Failed to connect to the WayVR IPC: {}", e))?;
|
||||||
let sender = Arc::new(Mutex::new(stream));
|
|
||||||
|
let async_stream = interprocess_stream_to_async(ip_stream)?;
|
||||||
|
let receiver = Arc::new(Mutex::new(async_stream.clone()));
|
||||||
|
let sender = Arc::new(Mutex::new(async_stream));
|
||||||
|
|
||||||
let (cancel_tx, cancel_rx) = async_channel::bounded(1);
|
let (cancel_tx, cancel_rx) = async_channel::bounded(1);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue