From e38bfdcfd54a27613eaa2e364b394bbdd99b74ae Mon Sep 17 00:00:00 2001 From: Samuel Dai Date: Fri, 20 Sep 2024 09:55:00 +0800 Subject: [PATCH] Feature/network-syscall (#931) --- kernel/src/net/socket/inet/stream/inner.rs | 15 +++++++++------ kernel/src/net/socket/inet/stream/mod.rs | 4 +++- kernel/src/net/socket/unix/mod.rs | 7 ++----- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/kernel/src/net/socket/inet/stream/inner.rs b/kernel/src/net/socket/inet/stream/inner.rs index 7d2b80b8c..46c469885 100644 --- a/kernel/src/net/socket/inet/stream/inner.rs +++ b/kernel/src/net/socket/inet/stream/inner.rs @@ -221,12 +221,6 @@ pub struct Listening { impl Listening { pub fn accept(&mut self) -> Result<(Established, smoltcp::wire::IpEndpoint), SystemError> { - let local_endpoint = self.inners[0] - .with::(|socket| socket.local_endpoint()) - .ok_or_else(|| { - log::error!("A Listening Tcp With No Local Endpoint"); - EINVAL - })?; let connected: &mut socket::inet::BoundInner = self .inners @@ -236,6 +230,15 @@ impl Listening { }) .ok_or(EAGAIN_OR_EWOULDBLOCK)?; + let local_endpoint = connected + .with::(|socket| socket.local_endpoint()) + .ok_or_else(|| { + log::error!("A Connected Tcp With No Local Endpoint"); + EINVAL + })?; + + log::debug!("local at {:?}", local_endpoint); + let mut new_listen = socket::inet::BoundInner::bind( new_listen_smoltcp_socket(local_endpoint), &local_endpoint.addr, diff --git a/kernel/src/net/socket/inet/stream/mod.rs b/kernel/src/net/socket/inet/stream/mod.rs index bb9c05968..d723f016a 100644 --- a/kernel/src/net/socket/inet/stream/mod.rs +++ b/kernel/src/net/socket/inet/stream/mod.rs @@ -104,6 +104,7 @@ impl TcpSocket { } pub fn try_accept(&self) -> Result<(Arc, smoltcp::wire::IpEndpoint), SystemError> { + poll_ifaces(); match self.inner.write().as_mut().expect("Tcp Inner is None") { Inner::Listening(listening) => listening.accept().map(|(stream, remote)| { ( @@ -215,7 +216,7 @@ impl TcpSocket { // should only call on accept fn is_acceptable(&self) -> bool { - self.poll() & EP::EPOLLIN.bits() as usize != 0 + (self.poll() & EP::EPOLLIN.bits() as usize) != 0 } } @@ -258,6 +259,7 @@ impl Socket for TcpSocket { } else { loop { wq_wait_event_interruptible!(self.wait_queue, self.is_acceptable(), {})?; + // log::debug!("TcpSocket::accept: wake up"); match self.try_accept() { Err(EAGAIN_OR_EWOULDBLOCK) => continue, result => break result, diff --git a/kernel/src/net/socket/unix/mod.rs b/kernel/src/net/socket/unix/mod.rs index 8dcd2b551..4ebd00658 100644 --- a/kernel/src/net/socket/unix/mod.rs +++ b/kernel/src/net/socket/unix/mod.rs @@ -14,16 +14,13 @@ fn create_unix_socket( sock_type: Type, ) -> Result, SystemError> { match sock_type { - Type::Stream |Type::Datagram=> { + Type::Stream | Type::Datagram => { stream::StreamSocket::new_inode() }, - Type::SeqPacket |Type::Datagram=>{ + Type::SeqPacket => { // Ok(seqpacket::SeqpacketSocket::new(false)) seqpacket::SeqpacketSocket::new_inode(false) }, - _ => { - Err(EPROTONOSUPPORT) - } _ => Err(EPROTONOSUPPORT), } }