forked from arcnmx/qapi-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents.rs
30 lines (25 loc) · 865 Bytes
/
events.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#[cfg(feature = "qmp")]
mod main {
use std::env::args;
use tokio_uds::UnixStream;
use tokio::prelude::*;
use tokio::run;
use tokio_qapi;
pub fn main() {
::env_logger::init();
let socket_addr = args().nth(1).expect("argument: QMP socket path");
run(UnixStream::connect(socket_addr)
.map(|stream| tokio_qapi::event_stream(stream))
.and_then(|(stream, events)| tokio_qapi::qmp_handshake(stream).map(|stream| (events, stream)))
.and_then(|(events, (caps, _stream))| {
println!("{:#?}", caps);
events.for_each(|e| Ok(println!("Got event {:#?}", e)))
}).map_err(|e| panic!("Failed with {:?}", e))
);
}
}
#[cfg(not(feature = "qmp"))]
mod main {
pub fn main() { panic!("requires feature qmp") }
}
fn main() { main::main() }