diff options
author | Alyssa Ross <hi@alyssa.is> | 2020-03-13 04:49:34 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2020-06-15 09:36:32 +0000 |
commit | c8ea9a839e28254474000729fa522b51fa860925 (patch) | |
tree | eebdcaf1556ce8882552f21efa686d21813c67f4 /src | |
parent | 29dd8155e7bf1698a035b1f17be6e9cc225e7445 (diff) | |
download | crosvm-c8ea9a839e28254474000729fa522b51fa860925.tar crosvm-c8ea9a839e28254474000729fa522b51fa860925.tar.gz crosvm-c8ea9a839e28254474000729fa522b51fa860925.tar.bz2 crosvm-c8ea9a839e28254474000729fa522b51fa860925.tar.lz crosvm-c8ea9a839e28254474000729fa522b51fa860925.tar.xz crosvm-c8ea9a839e28254474000729fa522b51fa860925.tar.zst crosvm-c8ea9a839e28254474000729fa522b51fa860925.zip |
poly_msg_socket
we're gonna need this to send all of VirtioDevice over a socket
Diffstat (limited to 'src')
-rw-r--r-- | src/linux.rs | 5 | ||||
-rw-r--r-- | src/wl.rs | 25 |
2 files changed, 19 insertions, 11 deletions
diff --git a/src/linux.rs b/src/linux.rs index 6f0e19b..7cb4b9c 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -40,6 +40,7 @@ use io_jail::{self, Minijail}; use kvm::*; use msg_socket::{MsgError, MsgReceiver, MsgResult, MsgSender, MsgSocket}; use net_util::{Error as NetError, MacAddress, Tap}; +use poly_msg_socket::PolyMsgSocket; use remain::sorted; use resources::{Alloc, MmioType, SystemAllocator}; use sync::{Condvar, Mutex}; @@ -85,7 +86,7 @@ pub enum Error { BuildVm(<Arch as LinuxArch>::Error), ChownTpmStorage(sys_util::Error), CloneEventFd(sys_util::Error), - ControllerCreate(MsgError), + ControllerCreate(poly_msg_socket::Error), CreateAc97(devices::PciDeviceError), CreateConsole(arch::serial::Error), CreateDiskError(disk::Error), @@ -767,7 +768,7 @@ fn create_wayland_device( let mut path = std::env::var("XDG_RUNTIME_DIR").expect("XDG_RUNTIME_DIR missing"); path.push_str("/crosvm-wl.sock"); let seq_socket = UnixSeqpacket::connect(&path).expect("connect failed"); - let msg_socket = MsgSocket::new(seq_socket); + let msg_socket = PolyMsgSocket::new(seq_socket); let dev = virtio::Controller::create( cfg.wayland_socket_paths.clone(), socket, diff --git a/src/wl.rs b/src/wl.rs index 77cf86c..333be87 100644 --- a/src/wl.rs +++ b/src/wl.rs @@ -1,7 +1,11 @@ // SPDX-License-Identifier: BSD-3-Clause -use devices::virtio::{InterruptProxy, InterruptProxyEvent, Request, Response, VirtioDevice, Wl}; -use msg_socket::{MsgReceiver, MsgSender, MsgSocket}; +use devices::virtio::{ + BincodeRequest, BincodeResponse, InterruptProxy, InterruptProxyEvent, MsgOnSocketRequest, + MsgOnSocketResponse, VirtioDevice, Wl, +}; +use msg_socket::MsgSocket; +use poly_msg_socket::PolyMsgSocket; use std::collections::BTreeMap; use std::fs::remove_file; use sys_util::{error, net::UnixSeqpacketListener, warn, GuestMemory}; @@ -11,7 +15,8 @@ pub use aarch64::{arch_memory_regions, MemoryParams}; #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] pub use x86_64::{arch_memory_regions, MemoryParams}; -type Socket = MsgSocket<Response, Request>; +type Socket = + PolyMsgSocket<MsgOnSocketResponse, MsgOnSocketRequest, BincodeResponse, BincodeRequest>; fn main() { eprintln!("hello world"); @@ -25,10 +30,12 @@ fn main() { // Receive connection from crosvm. let conn = server.accept().expect("accept failed"); - let msg_socket: Socket = MsgSocket::new(conn); + let msg_socket: Socket = PolyMsgSocket::new(conn); let vm_socket = match msg_socket.recv() { - Ok(Request::Create { vm_socket }) => MsgSocket::new(vm_socket.owned()), + Ok(poly_msg_socket::Value::MsgOnSocket(MsgOnSocketRequest::Create { vm_socket })) => { + MsgSocket::new(vm_socket.owned()) + } Ok(msg) => { panic!("received unexpected message: {:?}", msg); @@ -46,12 +53,12 @@ fn main() { loop { match msg_socket.recv() { - Ok(Request::Kill) => { + Ok(poly_msg_socket::Value::MsgOnSocket(MsgOnSocketRequest::Kill)) => { if let Some(wl) = wl.take() { // Will block until worker shuts down. drop(wl); - if let Err(e) = msg_socket.send(&Response::Kill) { + if let Err(e) = msg_socket.send(MsgOnSocketResponse::Kill) { error!("failed to send Response::Kill: {}", e); break; } @@ -60,7 +67,7 @@ fn main() { } } - Ok(Request::Activate { + Ok(poly_msg_socket::Value::MsgOnSocket(MsgOnSocketRequest::Activate { shm, interrupt, interrupt_resample_evt, @@ -68,7 +75,7 @@ fn main() { out_queue, in_queue_evt, out_queue_evt, - }) => { + })) => { let shm = shm.owned(); let regions = arch_memory_regions(MemoryParams { |