mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-27 19:33:23 +00:00
Fix clippy and compiler warings
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
20a90426a0
commit
9ca64c281e
@ -15,6 +15,7 @@ pub struct AnyUnboundSocket {
|
||||
pollee: Pollee,
|
||||
}
|
||||
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
pub(super) enum AnyRawSocket {
|
||||
Tcp(RawTcpSocket),
|
||||
Udp(RawUdpSocket),
|
||||
|
@ -2,6 +2,7 @@ use core::sync::atomic::{AtomicU64, Ordering};
|
||||
|
||||
use super::Ipv4Address;
|
||||
use crate::prelude::*;
|
||||
use alloc::collections::btree_map::Entry;
|
||||
use keyable_arc::KeyableWeak;
|
||||
use smoltcp::{
|
||||
iface::{SocketHandle, SocketSet},
|
||||
@ -62,8 +63,8 @@ impl IfaceCommon {
|
||||
fn alloc_ephemeral_port(&self) -> Result<u16> {
|
||||
let mut used_ports = self.used_ports.write();
|
||||
for port in IP_LOCAL_PORT_START..=IP_LOCAL_PORT_END {
|
||||
if !used_ports.contains_key(&port) {
|
||||
used_ports.insert(port, 0);
|
||||
if let Entry::Vacant(e) = used_ports.entry(port) {
|
||||
e.insert(0);
|
||||
return Ok(port);
|
||||
}
|
||||
}
|
||||
@ -74,7 +75,7 @@ impl IfaceCommon {
|
||||
let mut used_ports = self.used_ports.write();
|
||||
if let Some(used_times) = used_ports.get_mut(&port) {
|
||||
if *used_times == 0 || can_reuse {
|
||||
*used_times = *used_times + 1;
|
||||
*used_times += 1;
|
||||
} else {
|
||||
return_errno_with_message!(Errno::EADDRINUSE, "cannot bind port");
|
||||
}
|
||||
@ -163,7 +164,7 @@ impl IfaceCommon {
|
||||
}
|
||||
|
||||
fn insert_bound_socket(&self, socket: &Arc<AnyBoundSocket>) -> Result<()> {
|
||||
let weak_ref = KeyableWeak::from(Arc::downgrade(&socket));
|
||||
let weak_ref = KeyableWeak::from(Arc::downgrade(socket));
|
||||
let mut bound_sockets = self.bound_sockets.write();
|
||||
if bound_sockets.contains(&weak_ref) {
|
||||
return_errno_with_message!(Errno::EINVAL, "the socket is already bound");
|
||||
|
@ -28,7 +28,7 @@ impl IfaceLoopback {
|
||||
let config = Config::new();
|
||||
let mut interface = smoltcp::iface::Interface::new(config, &mut loopback);
|
||||
interface.update_ip_addrs(|ip_addrs| {
|
||||
debug_assert!(ip_addrs.len() == 0);
|
||||
debug_assert!(ip_addrs.is_empty());
|
||||
let ip_addr = IpCidr::new(LOOPBACK_ADDRESS, LOOPBACK_ADDRESS_PREFIX_LEN);
|
||||
ip_addrs.push(ip_addr).unwrap();
|
||||
});
|
||||
|
@ -21,22 +21,16 @@ impl BindPortConfig {
|
||||
} else {
|
||||
Self::Specified(port)
|
||||
}
|
||||
} else if can_reuse {
|
||||
return_errno_with_message!(Errno::EINVAL, "invalid bind port config");
|
||||
} else {
|
||||
if can_reuse {
|
||||
return_errno_with_message!(Errno::EINVAL, "invalid bind port config");
|
||||
} else {
|
||||
Self::Ephemeral
|
||||
}
|
||||
Self::Ephemeral
|
||||
};
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
pub(super) fn can_reuse(&self) -> bool {
|
||||
if let Self::CanReuse(_) = self {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
matches!(self, Self::CanReuse(_))
|
||||
}
|
||||
|
||||
pub(super) fn port(&self) -> Option<u16> {
|
||||
|
@ -19,7 +19,7 @@ pub struct IfaceVirtio {
|
||||
|
||||
impl IfaceVirtio {
|
||||
pub fn new() -> Arc<Self> {
|
||||
let mut virtio_net = jinux_network::get_device(&(DEVICE_NAME).to_string()).unwrap();
|
||||
let virtio_net = jinux_network::get_device(&(DEVICE_NAME).to_string()).unwrap();
|
||||
let interface = {
|
||||
let mac_addr = virtio_net.lock().mac_addr();
|
||||
let ip_addr = IpCidr::new(wire::IpAddress::Ipv4(wire::Ipv4Address::UNSPECIFIED), 0);
|
||||
@ -33,7 +33,7 @@ impl IfaceVirtio {
|
||||
};
|
||||
let mut interface = smoltcp::iface::Interface::new(config, &mut **virtio_net.lock());
|
||||
interface.update_ip_addrs(|ip_addrs| {
|
||||
debug_assert!(ip_addrs.len() == 0);
|
||||
debug_assert!(ip_addrs.is_empty());
|
||||
ip_addrs.push(ip_addr).unwrap();
|
||||
});
|
||||
interface
|
||||
|
@ -37,11 +37,7 @@ enum Inner {
|
||||
|
||||
impl Inner {
|
||||
fn is_bound(&self) -> bool {
|
||||
if let Inner::Bound { .. } = self {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
matches!(self, Inner::Bound { .. })
|
||||
}
|
||||
|
||||
fn bind(&mut self, endpoint: IpEndpoint) -> Result<()> {
|
||||
@ -91,7 +87,7 @@ impl Inner {
|
||||
remote_endpoint, ..
|
||||
} = self
|
||||
{
|
||||
remote_endpoint.clone()
|
||||
*remote_endpoint
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ impl Inner {
|
||||
|
||||
fn bound_socket(&self) -> Option<&Arc<AnyBoundSocket>> {
|
||||
match self {
|
||||
Inner::Bound(bound_socket) => Some(&bound_socket),
|
||||
Inner::Bound(bound_socket) => Some(bound_socket),
|
||||
Inner::Connecting { bound_socket, .. } => Some(bound_socket),
|
||||
_ => None,
|
||||
}
|
||||
@ -96,8 +96,7 @@ impl Inner {
|
||||
|
||||
fn local_endpoint(&self) -> Option<IpEndpoint> {
|
||||
self.bound_socket()
|
||||
.map(|socket| socket.local_endpoint())
|
||||
.flatten()
|
||||
.and_then(|socket| socket.local_endpoint())
|
||||
}
|
||||
|
||||
fn remote_endpoint(&self) -> Option<IpEndpoint> {
|
||||
|
@ -105,7 +105,7 @@ impl ListenStream {
|
||||
backlog_socket.poll(mask, poller);
|
||||
}
|
||||
}
|
||||
return IoEvents::empty();
|
||||
IoEvents::empty()
|
||||
}
|
||||
|
||||
fn bound_socket(&self) -> Arc<AnyBoundSocket> {
|
||||
|
@ -52,7 +52,7 @@ impl Endpoint {
|
||||
}
|
||||
|
||||
pub(super) fn peer_addr(&self) -> Option<UnixSocketAddrBound> {
|
||||
self.0.peer.upgrade().map(|peer| peer.addr()).flatten()
|
||||
self.0.peer.upgrade().and_then(|peer| peer.addr())
|
||||
}
|
||||
|
||||
pub(super) fn is_nonblocking(&self) -> bool {
|
||||
|
@ -205,7 +205,7 @@ fn create_keyable_inode(dentry: &Arc<Dentry>) -> KeyableWeak<dyn Inode> {
|
||||
}
|
||||
|
||||
pub(super) fn unregister_backlog(addr: &UnixSocketAddrBound) {
|
||||
BACKLOG_TABLE.remove_backlog(&addr);
|
||||
BACKLOG_TABLE.remove_backlog(addr);
|
||||
}
|
||||
|
||||
pub(super) fn push_incoming(
|
||||
|
@ -2,6 +2,6 @@ mod connected;
|
||||
mod endpoint;
|
||||
mod init;
|
||||
mod listener;
|
||||
mod stream;
|
||||
mod socket;
|
||||
|
||||
pub use stream::UnixStreamSocket;
|
||||
pub use socket::UnixStreamSocket;
|
||||
|
@ -233,10 +233,8 @@ impl Socket for UnixStreamSocket {
|
||||
};
|
||||
|
||||
match connected.peer_addr() {
|
||||
None => return Ok(SocketAddr::Unix(UnixSocketAddr::Path(String::new()))),
|
||||
Some(peer_addr) => {
|
||||
return Ok(SocketAddr::from(peer_addr.clone()));
|
||||
}
|
||||
None => Ok(SocketAddr::Unix(UnixSocketAddr::Path(String::new()))),
|
||||
Some(peer_addr) => Ok(SocketAddr::from(peer_addr.clone())),
|
||||
}
|
||||
}
|
||||
|
||||
@ -295,5 +293,5 @@ fn lookup_socket_file(path: &str) -> Result<Arc<Dentry>> {
|
||||
if !dentry.inode_mode().is_readable() || !dentry.inode_mode().is_writable() {
|
||||
return_errno_with_message!(Errno::EACCES, "the socket cannot be read or written")
|
||||
}
|
||||
return Ok(dentry);
|
||||
Ok(dentry)
|
||||
}
|
Reference in New Issue
Block a user