Skip to content

Commit 97980bf

Browse files
committed
stamp: putting back the unix stream receiver when escaping from function
1 parent 7f8c808 commit 97980bf

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

crates/sb_core/net.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,18 @@ pub async fn op_net_accept(
108108
if rx.is_none() {
109109
return Err(bad_resource("unix channel receiver is already used"));
110110
}
111-
let mut rx = rx.unwrap();
111+
112+
let rx = rx.unwrap();
113+
let mut rx = scopeguard::guard(rx, {
114+
let state = state.clone();
115+
move |value| {
116+
let mut op_state = state.borrow_mut();
117+
op_state.put::<mpsc::UnboundedReceiver<(
118+
tokio::net::UnixStream,
119+
Option<watch::Receiver<ConnSync>>,
120+
)>>(value);
121+
}
122+
});
112123

113124
let Some((unix_stream, conn_sync)) = rx.recv().await else {
114125
return Err(bad_resource("unix stream channel is closed"));
@@ -119,10 +130,9 @@ pub async fn op_net_accept(
119130

120131
// since the op state was dropped before,
121132
// reborrow and add the channel receiver again
122-
let mut op_state = state.borrow_mut();
123-
124-
op_state.put::<mpsc::UnboundedReceiver<(tokio::net::UnixStream, Option<watch::Receiver<ConnSync>>)>>(rx);
133+
drop(rx);
125134

135+
let mut op_state = state.borrow_mut();
126136
let rid = op_state.resource_table.add(resource);
127137

128138
if let Some(watcher) = conn_sync {

0 commit comments

Comments
 (0)