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

Loading…
Cancel
Save