Skip to content

Commit

Permalink
Feature/network-syscall (#931)
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuka007 committed Sep 20, 2024
1 parent 21e5982 commit e38bfdc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
15 changes: 9 additions & 6 deletions kernel/src/net/socket/inet/stream/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<smoltcp::socket::tcp::Socket, _, _>(|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
Expand All @@ -236,6 +230,15 @@ impl Listening {
})
.ok_or(EAGAIN_OR_EWOULDBLOCK)?;

let local_endpoint = connected
.with::<smoltcp::socket::tcp::Socket, _, _>(|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,
Expand Down
4 changes: 3 additions & 1 deletion kernel/src/net/socket/inet/stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ impl TcpSocket {
}

pub fn try_accept(&self) -> Result<(Arc<TcpSocket>, 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)| {
(
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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,
Expand Down
7 changes: 2 additions & 5 deletions kernel/src/net/socket/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ fn create_unix_socket(
sock_type: Type,
) -> Result<Arc<Inode>, 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),
}
}
Expand Down

0 comments on commit e38bfdc

Please sign in to comment.