Avoid unused variables in the network module

This commit is contained in:
Ruihan Li 2024-06-18 16:05:20 +08:00 committed by Tate, Hongliang Tian
parent 94e043ac8d
commit 5eefd600cc
18 changed files with 34 additions and 79 deletions

View File

@ -1,13 +1,10 @@
// SPDX-License-Identifier: MPL-2.0
#![allow(dead_code)]
use super::{Iface, IpAddress, IpEndpoint};
use crate::{events::Observer, prelude::*};
pub type RawTcpSocket = smoltcp::socket::tcp::Socket<'static>;
pub type RawUdpSocket = smoltcp::socket::udp::Socket<'static>;
pub type RawSocketHandle = smoltcp::iface::SocketHandle;
pub struct AnyUnboundSocket {
socket_family: AnyRawSocket,

View File

@ -1,9 +1,7 @@
// SPDX-License-Identifier: MPL-2.0
#![allow(unused_variables)]
use smoltcp::{
iface::{Config, Routes},
iface::Config,
phy::{Loopback, Medium},
wire::IpCidr,
};
@ -27,7 +25,6 @@ impl IfaceLoopback {
pub fn new() -> Arc<Self> {
let mut loopback = Loopback::new(Medium::Ip);
let interface = {
let routes = Routes::new();
let config = Config::new();
let mut interface = smoltcp::iface::Interface::new(config, &mut loopback);
interface.update_ip_addrs(|ip_addrs| {

View File

@ -1,11 +1,9 @@
// SPDX-License-Identifier: MPL-2.0
#![allow(unused_variables)]
use aster_network::AnyNetworkDevice;
use aster_virtio::device::network::DEVICE_NAME;
use smoltcp::{
iface::{Config, Routes, SocketHandle, SocketSet},
iface::{Config, SocketHandle, SocketSet},
socket::dhcpv4,
wire::{self, IpCidr},
};
@ -26,7 +24,6 @@ impl IfaceVirtio {
let interface = {
let mac_addr = virtio_net.lock().mac_addr();
let ip_addr = IpCidr::new(wire::IpAddress::Ipv4(wire::Ipv4Address::UNSPECIFIED), 0);
let routes = Routes::new();
let config = {
let mut config = Config::new();
config.hardware_addr = Some(wire::HardwareAddress::Ethernet(

View File

@ -1,7 +1,5 @@
// SPDX-License-Identifier: MPL-2.0
#![allow(unused_variables)]
use smoltcp::socket::udp::{RecvError, SendError};
use crate::{
@ -39,7 +37,7 @@ impl BoundDatagram {
self.remote_endpoint = Some(*endpoint)
}
pub fn try_recv(&self, buf: &mut [u8], flags: SendRecvFlags) -> Result<(usize, IpEndpoint)> {
pub fn try_recv(&self, buf: &mut [u8], _flags: SendRecvFlags) -> Result<(usize, IpEndpoint)> {
let result = self
.bound_socket
.raw_with(|socket: &mut RawUdpSocket| socket.recv_slice(buf));
@ -51,7 +49,12 @@ impl BoundDatagram {
}
}
pub fn try_send(&self, buf: &[u8], remote: &IpEndpoint, flags: SendRecvFlags) -> Result<usize> {
pub fn try_send(
&self,
buf: &[u8],
remote: &IpEndpoint,
_flags: SendRecvFlags,
) -> Result<usize> {
let result = self.bound_socket.raw_with(|socket: &mut RawUdpSocket| {
if socket.payload_send_capacity() < buf.len() {
return None;

View File

@ -1,7 +1,5 @@
// SPDX-License-Identifier: MPL-2.0
#![allow(unused_variables)]
use core::sync::atomic::{AtomicBool, Ordering};
use takeable::Takeable;
@ -301,7 +299,7 @@ impl Socket for DatagramSocket {
fn addr(&self) -> Result<SocketAddr> {
let inner = self.inner.read();
match inner.as_ref() {
Inner::Unbound(unbound_datagram) => Ok(UNSPECIFIED_LOCAL_ENDPOINT.into()),
Inner::Unbound(_) => Ok(UNSPECIFIED_LOCAL_ENDPOINT.into()),
Inner::Bound(bound_datagram) => Ok(bound_datagram.local_endpoint().into()),
}
}
@ -373,7 +371,7 @@ impl Socket for DatagramSocket {
}
impl Observer<()> for DatagramSocket {
fn on_events(&self, events: &()) {
fn on_events(&self, _events: &()) {
self.update_io_events();
}
}

View File

@ -1,7 +1,5 @@
// SPDX-License-Identifier: MPL-2.0
#![allow(unused_variables)]
use alloc::sync::Weak;
use smoltcp::socket::tcp::{RecvError, SendError};
@ -45,7 +43,7 @@ impl ConnectedStream {
}
}
pub fn shutdown(&self, cmd: SockShutdownCmd) -> Result<()> {
pub fn shutdown(&self, _cmd: SockShutdownCmd) -> Result<()> {
// TODO: deal with cmd
self.bound_socket.raw_with(|socket: &mut RawTcpSocket| {
socket.close();
@ -53,7 +51,7 @@ impl ConnectedStream {
Ok(())
}
pub fn try_recv(&self, buf: &mut [u8], flags: SendRecvFlags) -> Result<usize> {
pub fn try_recv(&self, buf: &mut [u8], _flags: SendRecvFlags) -> Result<usize> {
let result = self
.bound_socket
.raw_with(|socket: &mut RawTcpSocket| socket.recv_slice(buf));
@ -68,7 +66,7 @@ impl ConnectedStream {
}
}
pub fn try_send(&self, buf: &[u8], flags: SendRecvFlags) -> Result<usize> {
pub fn try_send(&self, buf: &[u8], _flags: SendRecvFlags) -> Result<usize> {
let result = self
.bound_socket
.raw_with(|socket: &mut RawTcpSocket| socket.send_slice(buf));

View File

@ -1,7 +1,5 @@
// SPDX-License-Identifier: MPL-2.0
#![allow(unused_variables)]
use smoltcp::socket::tcp::ListenError;
use super::connected::ConnectedStream;
@ -66,9 +64,8 @@ impl ListenStream {
})?;
let active_backlog_socket = backlog_sockets.remove(index);
match BacklogSocket::new(&self.bound_socket) {
Ok(backlog_socket) => backlog_sockets.push(backlog_socket),
Err(err) => (),
if let Ok(backlog_socket) = BacklogSocket::new(&self.bound_socket) {
backlog_sockets.push(backlog_socket);
}
let remote_endpoint = active_backlog_socket.remote_endpoint().unwrap();

View File

@ -1,7 +1,5 @@
// SPDX-License-Identifier: MPL-2.0
#![allow(unused_variables)]
use core::sync::atomic::{AtomicBool, Ordering};
use connected::ConnectedStream;
@ -713,7 +711,7 @@ impl Socket for StreamSocket {
}
impl Observer<()> for StreamSocket {
fn on_events(&self, events: &()) {
fn on_events(&self, _events: &()) {
let conn_ready = self.update_io_events();
if conn_ready {

View File

@ -1,7 +1,5 @@
// SPDX-License-Identifier: MPL-2.0
#![allow(unused_variables)]
use self::options::SocketOption;
pub use self::util::{
options::LingerOption, send_recv_flags::SendRecvFlags, shutdown_cmd::SockShutdownCmd,
@ -18,17 +16,17 @@ pub mod vsock;
/// Operations defined on a socket.
pub trait Socket: FileLike + Send + Sync {
/// Assign the address specified by socket_addr to the socket
fn bind(&self, socket_addr: SocketAddr) -> Result<()> {
fn bind(&self, _socket_addr: SocketAddr) -> Result<()> {
return_errno_with_message!(Errno::EOPNOTSUPP, "bind() is not supported");
}
/// Build connection for a given address
fn connect(&self, socket_addr: SocketAddr) -> Result<()> {
fn connect(&self, _socket_addr: SocketAddr) -> Result<()> {
return_errno_with_message!(Errno::EOPNOTSUPP, "connect() is not supported");
}
/// Listen for connections on a socket
fn listen(&self, backlog: usize) -> Result<()> {
fn listen(&self, _backlog: usize) -> Result<()> {
return_errno_with_message!(Errno::EOPNOTSUPP, "listen() is not supported");
}
@ -38,7 +36,7 @@ pub trait Socket: FileLike + Send + Sync {
}
/// Shut down part of a full-duplex connection
fn shutdown(&self, cmd: SockShutdownCmd) -> Result<()> {
fn shutdown(&self, _cmd: SockShutdownCmd) -> Result<()> {
return_errno_with_message!(Errno::EOPNOTSUPP, "shutdown() is not supported");
}
@ -54,12 +52,12 @@ pub trait Socket: FileLike + Send + Sync {
/// Get options on the socket. The resulted option will put in the `option` parameter, if
/// this method returns success.
fn get_option(&self, option: &mut dyn SocketOption) -> Result<()> {
fn get_option(&self, _option: &mut dyn SocketOption) -> Result<()> {
return_errno_with_message!(Errno::EOPNOTSUPP, "getsockopt() is not supported");
}
/// Set options on the socket.
fn set_option(&self, option: &dyn SocketOption) -> Result<()> {
fn set_option(&self, _option: &dyn SocketOption) -> Result<()> {
return_errno_with_message!(Errno::EOPNOTSUPP, "setsockopt() is not supported");
}

View File

@ -1,7 +1,5 @@
// SPDX-License-Identifier: MPL-2.0
#![allow(dead_code)]
use super::endpoint::Endpoint;
use crate::{
events::IoEvents,
@ -27,10 +25,6 @@ impl Connected {
self.local_endpoint.peer_addr()
}
pub(super) fn is_bound(&self) -> bool {
self.addr().is_some()
}
pub(super) fn write(&self, buf: &[u8]) -> Result<usize> {
self.local_endpoint.write(buf)
}

View File

@ -1,7 +1,5 @@
// SPDX-License-Identifier: MPL-2.0
#![allow(unused_variables)]
use crate::{
events::IoEvents,
fs::utils::{Channel, Consumer, Producer, StatusFlags},

View File

@ -1,7 +1,5 @@
// SPDX-License-Identifier: MPL-2.0
#![allow(dead_code)]
use core::sync::atomic::{AtomicBool, Ordering};
use super::{connected::Connected, endpoint::Endpoint, listener::push_incoming};
@ -69,10 +67,6 @@ impl Init {
Ok(Connected::new(this_end))
}
pub(super) fn is_bound(&self) -> bool {
self.addr.lock().is_some()
}
pub(super) fn addr(&self) -> Option<UnixSocketAddrBound> {
self.addr.lock().clone()
}

View File

@ -1,8 +1,5 @@
// SPDX-License-Identifier: MPL-2.0
#![allow(dead_code)]
#![allow(unused_variables)]
use super::{
connected::Connected,
endpoint::Endpoint,
@ -37,10 +34,6 @@ impl UnixStreamSocket {
Self(RwLock::new(State::Init(Arc::new(init))))
}
pub(super) fn new_listen(listen: Listener) -> Self {
Self(RwLock::new(State::Listen(Arc::new(listen))))
}
pub(super) fn new_connected(connected: Connected) -> Self {
Self(RwLock::new(State::Connected(Arc::new(connected))))
}
@ -91,7 +84,7 @@ impl UnixStreamSocket {
status_flags.intersection(SUPPORTED_FLAGS)
}
fn send(&self, buf: &[u8], flags: SendRecvFlags) -> Result<usize> {
fn send(&self, buf: &[u8], _flags: SendRecvFlags) -> Result<usize> {
let connected = match &*self.0.read() {
State::Connected(connected) => connected.clone(),
_ => return_errno_with_message!(Errno::ENOTCONN, "the socket is not connected"),
@ -100,7 +93,7 @@ impl UnixStreamSocket {
connected.write(buf)
}
fn recv(&self, buf: &mut [u8], flags: SendRecvFlags) -> Result<usize> {
fn recv(&self, buf: &mut [u8], _flags: SendRecvFlags) -> Result<usize> {
let connected = match &*self.0.read() {
State::Connected(connected) => connected.clone(),
_ => return_errno_with_message!(Errno::ENOTCONN, "the socket is not connected"),

View File

@ -47,7 +47,7 @@ pub fn copy_message_from_user(io_vecs: &[IoVec]) -> Box<[u8]> {
// FIXME: short read should be allowed here
match io_vec.read_exact_from_user(dst) {
Ok(()) => total_bytes += io_vec.len(),
Err(e) => {
Err(_) => {
warn!("fails to copy message from user");
break;
}
@ -84,7 +84,7 @@ pub fn copy_message_to_user(io_vecs: &[IoVec], message: &[u8]) -> usize {
let src = &message[total_bytes..total_bytes + len];
match io_vec.write_to_user(src) {
Ok(len) => total_bytes += len,
Err(e) => {
Err(_) => {
warn!("fails to copy message to user");
break;
}

View File

@ -1,7 +1,5 @@
// SPDX-License-Identifier: MPL-2.0
#![allow(dead_code)]
use core::time::Duration;
use crate::{
@ -19,7 +17,6 @@ pub struct SocketOptionSet {
send_buf: u32,
recv_buf: u32,
linger: LingerOption,
keep_alive: bool,
}
impl SocketOptionSet {
@ -32,7 +29,6 @@ impl SocketOptionSet {
send_buf: SEND_BUF_LEN as u32,
recv_buf: RECV_BUF_LEN as u32,
linger: LingerOption::default(),
keep_alive: false,
}
}
}

View File

@ -198,7 +198,6 @@ impl VsockSpace {
/// Poll for each event from the driver
pub fn poll(&self) -> Result<()> {
let mut driver = self.driver.lock_irq_disabled();
let guest_cid = driver.guest_cid() as u32;
while let Some(event) = self.poll_single(&mut driver)? {
if !self.is_event_for_socket(&event) {
@ -249,14 +248,14 @@ impl VsockSpace {
connecting.update_info(&event);
connecting.add_events(IoEvents::IN);
}
VsockEventType::Disconnected { reason } => {
VsockEventType::Disconnected { .. } => {
let connected_sockets = self.connected_sockets.read_irq_disabled();
let Some(connected) = connected_sockets.get(&event.into()) else {
return_errno_with_message!(Errno::ENOTCONN, "the socket hasn't connected");
};
connected.set_peer_requested_shutdown();
}
VsockEventType::Received { length } => {}
VsockEventType::Received { .. } => {}
VsockEventType::CreditRequest => {
let connected_sockets = self.connected_sockets.read_irq_disabled();
let Some(connected) = connected_sockets.get(&event.into()) else {
@ -282,7 +281,7 @@ impl VsockSpace {
driver
.poll(|event, body| {
// Deal with Received before the buffer are recycled.
if let VsockEventType::Received { length } = event.event_type {
if let VsockEventType::Received { .. } = event.event_type {
// Only consider the connected socket and copy body to buffer
let connected_sockets = self.connected_sockets.read_irq_disabled();
let connected = connected_sockets.get(&event.into()).unwrap();
@ -294,6 +293,6 @@ impl VsockSpace {
}
Ok(Some(event))
})
.map_err(|e| Error::with_message(Errno::EIO, "driver poll failed"))
.map_err(|_| Error::with_message(Errno::EIO, "driver poll failed"))
}
}

View File

@ -92,7 +92,7 @@ impl Connected {
connection.is_local_shutdown()
}
pub fn shutdown(&self, cmd: SockShutdownCmd) -> Result<()> {
pub fn shutdown(&self, _cmd: SockShutdownCmd) -> Result<()> {
// TODO: deal with cmd
if self.should_close() {
let mut connection = self.connection.lock_irq_disabled();

View File

@ -124,7 +124,7 @@ impl VsockStreamSocket {
}
}
fn try_recv(&self, buf: &mut [u8], flags: SendRecvFlags) -> Result<(usize, SocketAddr)> {
fn try_recv(&self, buf: &mut [u8], _flags: SendRecvFlags) -> Result<(usize, SocketAddr)> {
let connected = match &*self.status.read() {
Status::Connected(connected) => connected.clone(),
Status::Init(_) | Status::Listen(_) => {
@ -162,14 +162,12 @@ impl FileLike for VsockStreamSocket {
fn read(&self, buf: &mut [u8]) -> Result<usize> {
// TODO: Set correct flags
let flags = SendRecvFlags::empty();
self.recv(buf, SendRecvFlags::empty()).map(|(len, _)| len)
}
fn write(&self, buf: &[u8]) -> Result<usize> {
// TODO: Set correct flags
let flags = SendRecvFlags::empty();
self.send(buf, flags)
self.send(buf, SendRecvFlags::empty())
}
fn poll(&self, mask: IoEvents, poller: Option<&Poller>) -> IoEvents {