mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-08 14:16:47 +00:00
can ctrl-c interupt from blocking accept
This commit is contained in:
parent
2e98aea6f5
commit
7cebb88792
@ -241,16 +241,19 @@ impl IfaceCommon {
|
||||
self.poll_at_ms.store(0, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
if has_events {
|
||||
// log::debug!("IfaceCommon::poll: has_events");
|
||||
// We never try to hold the write lock in the IRQ context, and we disable IRQ when
|
||||
// holding the write lock. So we don't need to disable IRQ when holding the read lock.
|
||||
self.bounds.read().iter().for_each(|bound_socket| {
|
||||
bound_socket.on_iface_events();
|
||||
// if has_events {
|
||||
|
||||
// log::debug!("IfaceCommon::poll: has_events");
|
||||
// We never try to hold the write lock in the IRQ context, and we disable IRQ when
|
||||
// holding the write lock. So we don't need to disable IRQ when holding the read lock.
|
||||
self.bounds.read().iter().for_each(|bound_socket| {
|
||||
bound_socket.on_iface_events();
|
||||
if has_events {
|
||||
bound_socket
|
||||
.wait_queue()
|
||||
.wakeup(Some(ProcessState::Blocked(true)));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// let closed_sockets = self
|
||||
// .closing_sockets
|
||||
@ -258,7 +261,7 @@ impl IfaceCommon {
|
||||
// .extract_if(|closing_socket| closing_socket.is_closed())
|
||||
// .collect::<Vec<_>>();
|
||||
// drop(closed_sockets);
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
pub fn update_ip_addrs(&self, ip_addrs: &[smoltcp::wire::IpCidr]) -> Result<(), SystemError> {
|
||||
|
@ -440,4 +440,13 @@ impl Inner {
|
||||
Inner::Established(est) => est.with_mut(|socket| socket.recv_capacity()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn iface(&self) -> Option<&alloc::sync::Arc<dyn crate::driver::net::Iface>> {
|
||||
match self {
|
||||
Inner::Init(_) => None,
|
||||
Inner::Connecting(conn) => Some(conn.inner.iface()),
|
||||
Inner::Listening(listen) => Some(listen.inners[0].iface()),
|
||||
Inner::Established(est) => Some(est.inner.iface()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -185,11 +185,15 @@ impl TcpSocket {
|
||||
}
|
||||
|
||||
pub fn try_recv(&self, buf: &mut [u8]) -> Result<usize, SystemError> {
|
||||
poll_ifaces();
|
||||
match self.inner.read().as_ref().expect("Tcp Inner is None") {
|
||||
Inner::Established(inner) => inner.recv_slice(buf),
|
||||
_ => Err(EINVAL),
|
||||
}
|
||||
self.inner.read().as_ref().map(|inner| {
|
||||
inner.iface().unwrap().poll();
|
||||
let result = match inner {
|
||||
Inner::Established(inner) => inner.recv_slice(buf),
|
||||
_ => Err(EINVAL),
|
||||
};
|
||||
inner.iface().unwrap().poll();
|
||||
result
|
||||
}).unwrap()
|
||||
}
|
||||
|
||||
pub fn try_send(&self, buf: &[u8]) -> Result<usize, SystemError> {
|
||||
@ -221,6 +225,7 @@ impl TcpSocket {
|
||||
// should only call on accept
|
||||
fn is_acceptable(&self) -> bool {
|
||||
// (self.poll() & EP::EPOLLIN.bits() as usize) != 0
|
||||
self.inner.read().as_ref().unwrap().iface().unwrap().poll();
|
||||
EP::from_bits_truncate(self.poll() as u32).contains(EP::EPOLLIN)
|
||||
}
|
||||
}
|
||||
@ -255,7 +260,7 @@ impl Socket for TcpSocket {
|
||||
}
|
||||
|
||||
fn poll(&self) -> usize {
|
||||
self.pollee.load(core::sync::atomic::Ordering::Relaxed)
|
||||
self.pollee.load(core::sync::atomic::Ordering::SeqCst)
|
||||
}
|
||||
|
||||
fn listen(&self, backlog: usize) -> Result<(), SystemError> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user