Skip to content

Commit 4cd3582

Browse files
committed
Remove unnecessary Answer.active field.
Following upstream capnproto/capnproto@6074516
1 parent 42c361f commit 4cd3582

File tree

1 file changed

+10
-23
lines changed

1 file changed

+10
-23
lines changed

capnp-rpc/src/rpc.rs

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,6 @@ struct Answer<VatId>
240240
where
241241
VatId: 'static,
242242
{
243-
// True from the point when the Call message is received to the point when both the `Finish`
244-
// message has been received and the `Return` has been sent.
245-
active: bool,
246-
247243
return_has_been_sent: bool,
248244

249245
// Send pipelined calls here. Becomes null as soon as a `Finish` is received.
@@ -264,7 +260,6 @@ where
264260
impl<VatId> Answer<VatId> {
265261
fn new() -> Self {
266262
Self {
267-
active: false,
268263
return_has_been_sent: false,
269264
pipeline: None,
270265
redirected_results: None,
@@ -756,17 +751,17 @@ impl<VatId> ConnectionState<VatId> {
756751
};
757752

758753
let slots = &mut connection_state.answers.borrow_mut().slots;
759-
let answer = slots.entry(answer_id).or_insert_with(Answer::new);
760-
if answer.active {
754+
let hash_map::Entry::Vacant(slot) = slots.entry(answer_id) else {
761755
connection_state.release_exports(&result_exports)?;
762756
return Err(Error::failed("questionId is already in use".to_string()));
763-
}
764-
answer.active = true;
757+
};
758+
let mut answer = Answer::new();
765759
answer.return_has_been_sent = true;
766760
answer.result_exports = result_exports;
767761
answer.pipeline = Some(Box::new(SingleCapPipeline::new(
768762
connection_state.bootstrap_cap.clone(),
769763
)));
764+
slot.insert(answer);
770765

771766
let _ = response.send();
772767
Ok(())
@@ -785,11 +780,6 @@ impl<VatId> ConnectionState<VatId> {
785780
)));
786781
}
787782
Some(answer) => {
788-
if !answer.active {
789-
return Err(Error::failed(format!(
790-
"'Finish' for invalid question ID {answer_id}."
791-
)));
792-
}
793783
answer.received_finish.set(true);
794784

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

965955
{
966956
let slots = &mut connection_state.answers.borrow_mut().slots;
967-
let answer = slots.entry(question_id).or_insert(answer);
968-
if answer.active {
957+
let hash_map::Entry::Vacant(slot) = slots.entry(question_id) else {
969958
return Err(Error::failed("questionId is already in use".to_string()));
970-
}
971-
answer.active = true;
959+
};
960+
slot.insert(answer);
972961
}
973962

974963
let call_promise =
@@ -1537,11 +1526,9 @@ impl<VatId> ConnectionState<VatId> {
15371526
let promised_answer = receiver_answer?;
15381527
let question_id = promised_answer.get_question_id();
15391528
if let Some(answer) = state.answers.borrow().slots.get(&question_id) {
1540-
if answer.active {
1541-
if let Some(ref pipeline) = answer.pipeline {
1542-
let ops = to_pipeline_ops(promised_answer.get_transform()?)?;
1543-
return Ok(Some(pipeline.get_pipelined_cap(&ops)));
1544-
}
1529+
if let Some(ref pipeline) = answer.pipeline {
1530+
let ops = to_pipeline_ops(promised_answer.get_transform()?)?;
1531+
return Ok(Some(pipeline.get_pipelined_cap(&ops)));
15451532
}
15461533
}
15471534
Ok(Some(broken::new_cap(Error::failed(

0 commit comments

Comments
 (0)