1
0
Fork 0
forked from wry/wry

autocommit 2022-01-06 19:08:32 CET

This commit is contained in:
Julian Orth 2022-01-06 19:08:32 +01:00
parent cbbc41a463
commit 4a939477a2
51 changed files with 3438 additions and 207 deletions

View file

@ -1,4 +1,4 @@
use crate::client::{Client, ClientError, WlEvent};
use crate::client::{AddObj, Client, ClientError, WlEvent};
use crate::object::ObjectId;
use crate::utils::buffd::{BufFdIn, BufFdOut, MsgFormatter, MsgParser};
use crate::utils::oneshot::OneshotRx;
@ -10,12 +10,15 @@ use std::rc::Rc;
pub async fn client(data: Rc<Client>, shutdown: OneshotRx<()>) {
let mut recv = data.state.eng.spawn(receive(data.clone())).fuse();
let mut dispatch_fr = data.state.eng.spawn(dispatch_fr(data.clone())).fuse();
let _send = data.state.eng.spawn(send(data.clone()));
select! {
_ = recv => { },
_ = dispatch_fr => { },
_ = shutdown.fuse() => { },
}
drop(recv);
drop(dispatch_fr);
if !data.shutdown_sent.get() {
data.events.push(WlEvent::Shutdown);
}
@ -25,12 +28,36 @@ pub async fn client(data: Rc<Client>, shutdown: OneshotRx<()>) {
log::error!("Could not shut down client {} within 5 seconds", data.id.0);
}
Err(e) => {
log::error!("Could not create a timeout: {:#}", e);
log::error!("Could not create a timeout: {:#}", anyhow!(e));
}
}
data.state.clients.kill(data.id);
}
async fn dispatch_fr(data: Rc<Client>) {
loop {
let mut fr = data.dispatch_frame_requests.pop().await;
loop {
if let Err(e) = data.event(fr.done()).await {
log::error!("Could not dispatch frame event: {:#}", anyhow!(e));
return;
}
if let Err(e) = data.remove_obj(&*fr).await {
log::error!("Could not remove frame object: {:#}", anyhow!(e));
return;
}
fr = match data.dispatch_frame_requests.try_pop() {
Some(f) => f,
_ => break,
};
}
if let Err(e) = data.event2(WlEvent::Flush).await {
log::error!("Could not dispatch frame event: {:#}", anyhow!(e));
return;
}
}
}
async fn receive(data: Rc<Client>) {
let display = data.display().unwrap();
let recv = async {