can ctrl-c interupt from blocking accept

This commit is contained in:
Samuka007 2024-10-14 12:01:32 +00:00
parent 2e98aea6f5
commit 7cebb88792
3 changed files with 31 additions and 14 deletions

View File

@ -241,16 +241,19 @@ impl IfaceCommon {
self.poll_at_ms.store(0, Ordering::Relaxed); self.poll_at_ms.store(0, Ordering::Relaxed);
} }
if has_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 // log::debug!("IfaceCommon::poll: has_events");
// holding the write lock. So we don't need to disable IRQ when holding the read lock. // We never try to hold the write lock in the IRQ context, and we disable IRQ when
self.bounds.read().iter().for_each(|bound_socket| { // holding the write lock. So we don't need to disable IRQ when holding the read lock.
bound_socket.on_iface_events(); self.bounds.read().iter().for_each(|bound_socket| {
bound_socket.on_iface_events();
if has_events {
bound_socket bound_socket
.wait_queue() .wait_queue()
.wakeup(Some(ProcessState::Blocked(true))); .wakeup(Some(ProcessState::Blocked(true)));
}); }
});
// let closed_sockets = self // let closed_sockets = self
// .closing_sockets // .closing_sockets
@ -258,7 +261,7 @@ impl IfaceCommon {
// .extract_if(|closing_socket| closing_socket.is_closed()) // .extract_if(|closing_socket| closing_socket.is_closed())
// .collect::<Vec<_>>(); // .collect::<Vec<_>>();
// drop(closed_sockets); // drop(closed_sockets);
} // }
} }
pub fn update_ip_addrs(&self, ip_addrs: &[smoltcp::wire::IpCidr]) -> Result<(), SystemError> { pub fn update_ip_addrs(&self, ip_addrs: &[smoltcp::wire::IpCidr]) -> Result<(), SystemError> {

View File

@ -440,4 +440,13 @@ impl Inner {
Inner::Established(est) => est.with_mut(|socket| socket.recv_capacity()), 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()),
}
}
} }

View File

@ -185,11 +185,15 @@ impl TcpSocket {
} }
pub fn try_recv(&self, buf: &mut [u8]) -> Result<usize, SystemError> { pub fn try_recv(&self, buf: &mut [u8]) -> Result<usize, SystemError> {
poll_ifaces(); self.inner.read().as_ref().map(|inner| {
match self.inner.read().as_ref().expect("Tcp Inner is None") { inner.iface().unwrap().poll();
Inner::Established(inner) => inner.recv_slice(buf), let result = match inner {
_ => Err(EINVAL), 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> { pub fn try_send(&self, buf: &[u8]) -> Result<usize, SystemError> {
@ -221,6 +225,7 @@ impl TcpSocket {
// should only call on accept // should only call on accept
fn is_acceptable(&self) -> bool { fn is_acceptable(&self) -> bool {
// (self.poll() & EP::EPOLLIN.bits() as usize) != 0 // (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) EP::from_bits_truncate(self.poll() as u32).contains(EP::EPOLLIN)
} }
} }
@ -255,7 +260,7 @@ impl Socket for TcpSocket {
} }
fn poll(&self) -> usize { 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> { fn listen(&self, backlog: usize) -> Result<(), SystemError> {