Skip to content

Commit

Permalink
simplify release_export()
Browse files Browse the repository at this point in the history
  • Loading branch information
dwrensha committed Sep 22, 2024
1 parent bf80e2e commit aa27dbc
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions capnp-rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,30 +1170,21 @@ impl<VatId> ConnectionState<VatId> {
}

fn release_export(&self, id: ExportId, refcount: u32) -> ::capnp::Result<()> {
let mut erase_export = false;
let mut client_ptr = 0;
match self.exports.borrow_mut().find(id) {
Some(e) => {
if refcount > e.refcount {
return Err(Error::failed(
"Tried to drop export's refcount below zero.".to_string(),
));
} else {
e.refcount -= refcount;
if e.refcount == 0 {
erase_export = true;
client_ptr = e.client_hook.get_ptr();
}
}
}
None => {
return Err(Error::failed(
"Tried to release invalid export ID.".to_string(),
));
}
let mut exports = self.exports.borrow_mut();
let Some(e) = exports.find(id) else {
return Err(Error::failed(
"Tried to release invalid export ID.".to_string(),
));
};
if refcount > e.refcount {
return Err(Error::failed(
"Tried to drop export's refcount below zero.".to_string(),
));
}
if erase_export {
self.exports.borrow_mut().erase(id);
e.refcount -= refcount;
if e.refcount == 0 {
let client_ptr = e.client_hook.get_ptr();
exports.erase(id);
self.exports_by_cap.borrow_mut().remove(&client_ptr);
}
Ok(())
Expand Down

0 comments on commit aa27dbc

Please sign in to comment.