This commit is contained in:
Samuka007 2024-10-21 11:02:31 +00:00
parent e0c725556d
commit bca5197bdf
4 changed files with 20 additions and 10 deletions

View File

@ -117,5 +117,8 @@ use crate::net::socket;
use alloc::sync::Arc;
pub trait Family {
fn socket(stype: socket::PSOCK, protocol: u32) -> Result<Arc<socket::Inode>, system_error::SystemError>;
fn socket(
stype: socket::PSOCK,
protocol: u32,
) -> Result<Arc<socket::Inode>, system_error::SystemError>;
}

View File

@ -66,7 +66,7 @@ impl Init {
Init::Bound(_) => {
log::debug!("Already Bound");
Err(EINVAL)
},
}
}
}

View File

@ -73,7 +73,7 @@ impl TcpSocket {
writer.replace(any);
log::error!("TcpSocket::do_bind: not Init");
Err(EINVAL)
},
}
}
}
@ -234,11 +234,13 @@ impl Socket for TcpSocket {
fn get_name(&self) -> Result<Endpoint, SystemError> {
match self.inner.read().as_ref().expect("Tcp Inner is None") {
Inner::Init(Init::Unbound((_, v4))) => if *v4 {
Ok(Endpoint::Ip(UNSPECIFIED_LOCAL_ENDPOINT_V4))
} else {
Ok(Endpoint::Ip(UNSPECIFIED_LOCAL_ENDPOINT_V6))
},
Inner::Init(Init::Unbound((_, v4))) => {
if *v4 {
Ok(Endpoint::Ip(UNSPECIFIED_LOCAL_ENDPOINT_V4))
} else {
Ok(Endpoint::Ip(UNSPECIFIED_LOCAL_ENDPOINT_V6))
}
}
Inner::Init(Init::Bound((_, local))) => Ok(Endpoint::Ip(*local)),
Inner::Connecting(connecting) => Ok(Endpoint::Ip(connecting.get_name())),
Inner::Established(established) => Ok(Endpoint::Ip(established.local_endpoint())),

View File

@ -44,7 +44,8 @@ fn create_inet_socket(
pub struct Inet;
impl family::Family for Inet {
fn socket(stype: PSOCK, protocol: u32) -> Result<Arc<Inode>, SystemError> {
let socket = create_inet_socket(true, stype, smoltcp::wire::IpProtocol::from(protocol as u8))?;
let socket =
create_inet_socket(true, stype, smoltcp::wire::IpProtocol::from(protocol as u8))?;
Ok(Inode::new(socket))
}
}
@ -52,7 +53,11 @@ impl family::Family for Inet {
pub struct Inet6;
impl family::Family for Inet6 {
fn socket(stype: PSOCK, protocol: u32) -> Result<Arc<Inode>, SystemError> {
let socket = create_inet_socket(false, stype, smoltcp::wire::IpProtocol::from(protocol as u8))?;
let socket = create_inet_socket(
false,
stype,
smoltcp::wire::IpProtocol::from(protocol as u8),
)?;
Ok(Inode::new(socket))
}
}