mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-22 00:43:24 +00:00
Move impl Drop
to UNIX listeners
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
98e2a99195
commit
a2d94675eb
@ -58,6 +58,12 @@ impl Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Drop for Listener {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
unregister_backlog(self.backlog.addr())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static BACKLOG_TABLE: BacklogTable = BacklogTable::new();
|
static BACKLOG_TABLE: BacklogTable = BacklogTable::new();
|
||||||
|
|
||||||
struct BacklogTable {
|
struct BacklogTable {
|
||||||
@ -194,7 +200,7 @@ fn create_keyable_inode(dentry: &Arc<Dentry>) -> KeyableWeak<dyn Inode> {
|
|||||||
KeyableWeak::from(weak_inode)
|
KeyableWeak::from(weak_inode)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn unregister_backlog(addr: &UnixSocketAddrBound) {
|
fn unregister_backlog(addr: &UnixSocketAddrBound) {
|
||||||
BACKLOG_TABLE.remove_backlog(addr);
|
BACKLOG_TABLE.remove_backlog(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,12 +4,7 @@ use core::sync::atomic::AtomicBool;
|
|||||||
|
|
||||||
use atomic::Ordering;
|
use atomic::Ordering;
|
||||||
|
|
||||||
use super::{
|
use super::{connected::Connected, endpoint::Endpoint, init::Init, listener::Listener};
|
||||||
connected::Connected,
|
|
||||||
endpoint::Endpoint,
|
|
||||||
init::Init,
|
|
||||||
listener::{unregister_backlog, Listener},
|
|
||||||
};
|
|
||||||
use crate::{
|
use crate::{
|
||||||
events::{IoEvents, Observer},
|
events::{IoEvents, Observer},
|
||||||
fs::{
|
fs::{
|
||||||
@ -71,15 +66,6 @@ impl UnixStreamSocket {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bound_addr(&self) -> Option<UnixSocketAddrBound> {
|
|
||||||
let state = self.state.read();
|
|
||||||
match &*state {
|
|
||||||
State::Init(init) => init.addr().cloned(),
|
|
||||||
State::Listen(listen) => Some(listen.addr().clone()),
|
|
||||||
State::Connected(connected) => connected.addr().cloned(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn send(&self, buf: &[u8], flags: SendRecvFlags) -> Result<usize> {
|
fn send(&self, buf: &[u8], flags: SendRecvFlags) -> Result<usize> {
|
||||||
if self.is_nonblocking() {
|
if self.is_nonblocking() {
|
||||||
self.try_send(buf, flags)
|
self.try_send(buf, flags)
|
||||||
@ -344,18 +330,6 @@ impl Socket for UnixStreamSocket {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for UnixStreamSocket {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
let Some(bound_addr) = self.bound_addr() else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
if let State::Listen(_) = &*self.state.read() {
|
|
||||||
unregister_backlog(&bound_addr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn lookup_socket_file(path: &str) -> Result<Arc<Dentry>> {
|
fn lookup_socket_file(path: &str) -> Result<Arc<Dentry>> {
|
||||||
let dentry = {
|
let dentry = {
|
||||||
let current = current!();
|
let current = current!();
|
||||||
|
Reference in New Issue
Block a user