From bd02cdd8227819e8a3d2e07e62b108cea32cba4d Mon Sep 17 00:00:00 2001 From: lhw Date: Wed, 11 Dec 2024 20:06:30 +0800 Subject: [PATCH] add unix socket drop --- modules/ruxnet/src/unix.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/modules/ruxnet/src/unix.rs b/modules/ruxnet/src/unix.rs index 5436ab237..9136090b8 100644 --- a/modules/ruxnet/src/unix.rs +++ b/modules/ruxnet/src/unix.rs @@ -203,6 +203,10 @@ impl<'a> HashMapWarpper<'a> { pub fn get_mut(&mut self, id: usize) -> Option<&mut Arc>>> { self.inner.get_mut(&id) } + + pub fn remove(&mut self, id: usize) -> Option>>> { + self.inner.remove(&id) + } } static UNIX_TABLE: LazyInit> = LazyInit::new(); @@ -664,10 +668,12 @@ impl UnixSocket { } } - //TODO /// Shuts down the socket. pub fn shutdown(&self) -> LinuxResult { - unimplemented!() + let mut binding = UNIX_TABLE.write(); + let mut socket_inner = binding.get_mut(self.get_sockethandle()).unwrap().lock(); + socket_inner.set_state(UnixSocketStatus::Closed); + Ok(()) } /// Returns whether this socket is in nonblocking mode. @@ -696,6 +702,13 @@ impl UnixSocket { } } +impl Drop for UnixSocket { + fn drop(&mut self) { + self.shutdown(); + UNIX_TABLE.write().remove(self.get_sockethandle()); + } +} + /// Initializes the global UNIX socket table, `UNIX_TABLE`, for managing Unix domain sockets. pub(crate) fn init_unix() { UNIX_TABLE.init_by(RwLock::new(HashMapWarpper::new()));