Skip to content

Commit

Permalink
Merge pull request #155 from lhw2002426/multiprocess-loopback
Browse files Browse the repository at this point in the history
add unix socket drop
  • Loading branch information
ken4647 authored Dec 15, 2024
2 parents 6bc5b32 + bd02cdd commit 27bcc5d
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions modules/ruxnet/src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ impl<'a> HashMapWarpper<'a> {
pub fn get_mut(&mut self, id: usize) -> Option<&mut Arc<Mutex<UnixSocketInner<'a>>>> {
self.inner.get_mut(&id)
}

pub fn remove(&mut self, id: usize) -> Option<Arc<Mutex<UnixSocketInner<'a>>>> {
self.inner.remove(&id)
}
}
static UNIX_TABLE: LazyInit<RwLock<HashMapWarpper>> = LazyInit::new();

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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()));
Expand Down

0 comments on commit 27bcc5d

Please sign in to comment.