Skip to content

Commit 312348d

Browse files
committed
feat(driver,iocp): deregister from global port on drop
1 parent 0038769 commit 312348d

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

compio-driver/src/iocp/cp/global.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ impl GlobalPort {
3838
receiver
3939
}
4040

41+
pub fn deregister(&self, driver: usize) {
42+
self.drivers.remove(&driver);
43+
}
44+
4145
pub fn attach(&self, fd: RawFd) -> io::Result<()> {
4246
self.port.attach(fd)
4347
}
@@ -51,12 +55,9 @@ impl GlobalPort {
5155
}
5256

5357
pub fn push(&self, driver: usize, entry: Entry) {
54-
self.drivers
55-
.get(&driver)
56-
.expect("driver should register first")
57-
.value()
58-
.send(entry)
59-
.ok(); // It's OK if the driver has been dropped.
58+
if let Some(e) = self.drivers.get(&driver) {
59+
e.value().send(entry).ok(); // It's OK if the driver has been dropped.
60+
}
6061
}
6162
}
6263

@@ -146,6 +147,12 @@ impl Port {
146147
}
147148
}
148149

150+
impl Drop for Port {
151+
fn drop(&mut self) {
152+
self.port.deregister(self.id);
153+
}
154+
}
155+
149156
pub struct PortHandle {
150157
port: &'static GlobalPort,
151158
}

0 commit comments

Comments
 (0)