Extract run_unix_listener extension method
This commit is contained in:
parent
e4bace1793
commit
71aecea297
2 changed files with 19 additions and 6 deletions
|
|
@ -76,6 +76,18 @@ impl HostedBus {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait SharedHostedBus {
|
||||
async fn run_unix_listener(self, listener: tokio::net::UnixListener);
|
||||
}
|
||||
|
||||
impl SharedHostedBus for Arc<tokio::sync::Mutex<HostedBus>> {
|
||||
async fn run_unix_listener(self, listener: tokio::net::UnixListener) {
|
||||
while let Ok((socket, _remote_addr)) = listener.accept().await {
|
||||
self.lock().await.connect_unix(socket).await.unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct NameOwnerStream {
|
||||
_conn: zbus::Connection,
|
||||
stream: zbus::MessageStream,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
mod bus;
|
||||
mod vsock;
|
||||
|
||||
use bus::SharedHostedBus;
|
||||
use clap::Parser;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::Mutex;
|
||||
|
|
@ -30,13 +31,13 @@ async fn main() -> eyre::Result<()> {
|
|||
let vm_bus = Arc::new(Mutex::new(vm_bus));
|
||||
|
||||
// Direct access for the host (just trying things out)
|
||||
let unix_listener = tokio::net::UnixListener::bind("vmbus.sock")?;
|
||||
tokio::spawn(enclose! { (vm_bus) async move {
|
||||
while let Ok((socket, _remote_addr)) = unix_listener.accept().await {
|
||||
vm_bus.lock().await.connect_unix(socket).await.unwrap()
|
||||
}
|
||||
} });
|
||||
tokio::spawn(
|
||||
vm_bus
|
||||
.clone()
|
||||
.run_unix_listener(tokio::net::UnixListener::bind("vmbus.sock")?),
|
||||
);
|
||||
|
||||
// TODO: modprobe vhost_vsock first!
|
||||
// NOTE: Every individual D-Bus client inside of the VM is a new client here!
|
||||
vsock::ListenerBuilder::new(vsock::VsockAddr::new(vsock::VMADDR_CID_HOST, 4269))
|
||||
.with_label("VM Bus")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue