refactor server message handling

pull/574/head
Dmitry Sharshakov 3 years ago committed by Blaž Hrastnik
parent 541f7a0514
commit 9678df1c62

@ -167,52 +167,32 @@ impl Transport {
client_tx: &UnboundedSender<Payload>, client_tx: &UnboundedSender<Payload>,
msg: Payload, msg: Payload,
) -> Result<()> { ) -> Result<()> {
let (id, result) = match msg { match msg {
Payload::Response(Response { Payload::Response(Response {
success: true, ref success,
seq, ref seq,
request_seq, request_seq,
ref command,
ref message,
ref body,
.. ..
}) => { }) => {
let result = match success {
true => {
info!("<- DAP success ({}, in response to {})", seq, request_seq); info!("<- DAP success ({}, in response to {})", seq, request_seq);
if let Payload::Response(val) = msg { if let Payload::Response(val) = msg {
(request_seq, Ok(val)) Ok(val)
} else { } else {
unreachable!(); unreachable!();
} }
} }
Payload::Response(Response { false => {
success: false,
message,
body,
request_seq,
command,
..
}) => {
error!( error!(
"<- DAP error {:?} ({:?}) for command #{} {}", "<- DAP error {:?} ({:?}) for command #{} {}",
message, body, request_seq, command message, body, request_seq, command
); );
(
request_seq, Err(Error::Other(anyhow::format_err!("{:?}", body)))
Err(Error::Other(anyhow::format_err!("{:?}", body))),
)
}
Payload::Request(Request {
ref command,
ref seq,
..
}) => {
info!("<- DAP request {} #{}", command, seq);
client_tx.send(msg).expect("Failed to send");
return Ok(());
}
Payload::Event(Event {
ref event, ref seq, ..
}) => {
info!("<- DAP event {} #{}", event, seq);
client_tx.send(msg).expect("Failed to send");
return Ok(());
} }
}; };
@ -220,19 +200,37 @@ impl Transport {
.pending_requests .pending_requests
.lock() .lock()
.await .await
.remove(&id) .remove(&request_seq)
.expect("pending_request with id not found!"); .expect("pending_request with id not found!");
match tx.send(result).await { match tx.send(result).await {
Ok(_) => (), Ok(_) => (),
Err(_) => error!( Err(_) => error!(
"Tried sending response into a closed channel (id={:?}), original request likely timed out", "Tried sending response into a closed channel (id={:?}), original request likely timed out",
id request_seq
), ),
}; };
Ok(()) Ok(())
} }
Payload::Request(Request {
ref command,
ref seq,
..
}) => {
info!("<- DAP request {} #{}", command, seq);
client_tx.send(msg).expect("Failed to send");
Ok(())
}
Payload::Event(Event {
ref event, ref seq, ..
}) => {
info!("<- DAP event {} #{}", event, seq);
client_tx.send(msg).expect("Failed to send");
Ok(())
}
}
}
async fn recv( async fn recv(
transport: Arc<Self>, transport: Arc<Self>,

Loading…
Cancel
Save