Skip to content

Commit

Permalink
Remove unnecessary Answer.active field.
Browse files Browse the repository at this point in the history
Following upstream
capnproto/capnproto@6074516
  • Loading branch information
dwrensha committed Sep 2, 2024
1 parent 42c361f commit 4cd3582
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions capnp-rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,6 @@ struct Answer<VatId>
where
VatId: 'static,
{
// True from the point when the Call message is received to the point when both the `Finish`
// message has been received and the `Return` has been sent.
active: bool,

return_has_been_sent: bool,

// Send pipelined calls here. Becomes null as soon as a `Finish` is received.
Expand All @@ -264,7 +260,6 @@ where
impl<VatId> Answer<VatId> {
fn new() -> Self {
Self {
active: false,
return_has_been_sent: false,
pipeline: None,
redirected_results: None,
Expand Down Expand Up @@ -756,17 +751,17 @@ impl<VatId> ConnectionState<VatId> {
};

let slots = &mut connection_state.answers.borrow_mut().slots;
let answer = slots.entry(answer_id).or_insert_with(Answer::new);
if answer.active {
let hash_map::Entry::Vacant(slot) = slots.entry(answer_id) else {
connection_state.release_exports(&result_exports)?;
return Err(Error::failed("questionId is already in use".to_string()));
}
answer.active = true;
};
let mut answer = Answer::new();
answer.return_has_been_sent = true;
answer.result_exports = result_exports;
answer.pipeline = Some(Box::new(SingleCapPipeline::new(
connection_state.bootstrap_cap.clone(),
)));
slot.insert(answer);

let _ = response.send();
Ok(())
Expand All @@ -785,11 +780,6 @@ impl<VatId> ConnectionState<VatId> {
)));
}
Some(answer) => {
if !answer.active {
return Err(Error::failed(format!(
"'Finish' for invalid question ID {answer_id}."
)));
}
answer.received_finish.set(true);

if finish.get_release_result_caps() {
Expand Down Expand Up @@ -964,11 +954,10 @@ impl<VatId> ConnectionState<VatId> {

{
let slots = &mut connection_state.answers.borrow_mut().slots;
let answer = slots.entry(question_id).or_insert(answer);
if answer.active {
let hash_map::Entry::Vacant(slot) = slots.entry(question_id) else {
return Err(Error::failed("questionId is already in use".to_string()));
}
answer.active = true;
};
slot.insert(answer);
}

let call_promise =
Expand Down Expand Up @@ -1537,11 +1526,9 @@ impl<VatId> ConnectionState<VatId> {
let promised_answer = receiver_answer?;
let question_id = promised_answer.get_question_id();
if let Some(answer) = state.answers.borrow().slots.get(&question_id) {
if answer.active {
if let Some(ref pipeline) = answer.pipeline {
let ops = to_pipeline_ops(promised_answer.get_transform()?)?;
return Ok(Some(pipeline.get_pipelined_cap(&ops)));
}
if let Some(ref pipeline) = answer.pipeline {
let ops = to_pipeline_ops(promised_answer.get_transform()?)?;
return Ok(Some(pipeline.get_pipelined_cap(&ops)));
}
}
Ok(Some(broken::new_cap(Error::failed(
Expand Down

0 comments on commit 4cd3582

Please sign in to comment.