mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-22 06:42:32 +00:00
chore: address some clippy issues
Signed-off-by: Krzysztof Królczyk <Krzysztof.Krolczyk@o2.pl>
This commit is contained in:
parent
af694d233c
commit
9634dfd6c1
@ -33,14 +33,14 @@ pub use embassy_net_driver as driver;
|
|||||||
use embassy_net_driver::{Driver, LinkState};
|
use embassy_net_driver::{Driver, LinkState};
|
||||||
use embassy_sync::waitqueue::WakerRegistration;
|
use embassy_sync::waitqueue::WakerRegistration;
|
||||||
use embassy_time::{Instant, Timer};
|
use embassy_time::{Instant, Timer};
|
||||||
#[allow(unused_imports)]
|
|
||||||
use heapless::Vec;
|
use heapless::Vec;
|
||||||
#[cfg(feature = "dns")]
|
#[cfg(feature = "dns")]
|
||||||
pub use smoltcp::config::DNS_MAX_SERVER_COUNT;
|
pub use smoltcp::config::DNS_MAX_SERVER_COUNT;
|
||||||
#[cfg(feature = "multicast")]
|
#[cfg(feature = "multicast")]
|
||||||
pub use smoltcp::iface::MulticastError;
|
pub use smoltcp::iface::MulticastError;
|
||||||
#[allow(unused_imports)]
|
#[cfg(any(feature = "dns", feature = "dhcpv4"))]
|
||||||
use smoltcp::iface::{Interface, SocketHandle, SocketSet, SocketStorage};
|
use smoltcp::iface::SocketHandle;
|
||||||
|
use smoltcp::iface::{Interface, SocketSet, SocketStorage};
|
||||||
use smoltcp::phy::Medium;
|
use smoltcp::phy::Medium;
|
||||||
#[cfg(feature = "dhcpv4")]
|
#[cfg(feature = "dhcpv4")]
|
||||||
use smoltcp::socket::dhcpv4::{self, RetryConfig};
|
use smoltcp::socket::dhcpv4::{self, RetryConfig};
|
||||||
@ -379,11 +379,11 @@ fn to_smoltcp_hardware_address(addr: driver::HardwareAddress) -> (HardwareAddres
|
|||||||
|
|
||||||
impl<'d> Stack<'d> {
|
impl<'d> Stack<'d> {
|
||||||
fn with<R>(&self, f: impl FnOnce(&Inner) -> R) -> R {
|
fn with<R>(&self, f: impl FnOnce(&Inner) -> R) -> R {
|
||||||
f(&*self.inner.borrow())
|
f(&self.inner.borrow())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_mut<R>(&self, f: impl FnOnce(&mut Inner) -> R) -> R {
|
fn with_mut<R>(&self, f: impl FnOnce(&mut Inner) -> R) -> R {
|
||||||
f(&mut *self.inner.borrow_mut())
|
f(&mut self.inner.borrow_mut())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the hardware address of the network interface.
|
/// Get the hardware address of the network interface.
|
||||||
@ -642,7 +642,7 @@ impl<'d> Stack<'d> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Inner {
|
impl Inner {
|
||||||
#[allow(clippy::absurd_extreme_comparisons, dead_code)]
|
#[allow(clippy::absurd_extreme_comparisons)]
|
||||||
pub fn get_local_port(&mut self) -> u16 {
|
pub fn get_local_port(&mut self) -> u16 {
|
||||||
let res = self.next_local_port;
|
let res = self.next_local_port;
|
||||||
self.next_local_port = if res >= LOCAL_PORT_MAX { LOCAL_PORT_MIN } else { res + 1 };
|
self.next_local_port = if res >= LOCAL_PORT_MAX { LOCAL_PORT_MIN } else { res + 1 };
|
||||||
@ -732,7 +732,7 @@ impl Inner {
|
|||||||
debug!(" Default gateway: {:?}", config.gateway);
|
debug!(" Default gateway: {:?}", config.gateway);
|
||||||
|
|
||||||
unwrap!(addrs.push(IpCidr::Ipv4(config.address)).ok());
|
unwrap!(addrs.push(IpCidr::Ipv4(config.address)).ok());
|
||||||
gateway_v4 = config.gateway.into();
|
gateway_v4 = config.gateway;
|
||||||
#[cfg(feature = "dns")]
|
#[cfg(feature = "dns")]
|
||||||
for s in &config.dns_servers {
|
for s in &config.dns_servers {
|
||||||
debug!(" DNS server: {:?}", s);
|
debug!(" DNS server: {:?}", s);
|
||||||
@ -831,22 +831,19 @@ impl Inner {
|
|||||||
self.state_waker.wake();
|
self.state_waker.wake();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_mut)]
|
|
||||||
let mut apply_config = false;
|
|
||||||
|
|
||||||
#[cfg(feature = "dhcpv4")]
|
#[cfg(feature = "dhcpv4")]
|
||||||
if let Some(dhcp_handle) = self.dhcp_socket {
|
if let Some(dhcp_handle) = self.dhcp_socket {
|
||||||
let socket = self.sockets.get_mut::<dhcpv4::Socket>(dhcp_handle);
|
let socket = self.sockets.get_mut::<dhcpv4::Socket>(dhcp_handle);
|
||||||
|
|
||||||
if self.link_up {
|
let configure = if self.link_up {
|
||||||
if old_link_up != self.link_up {
|
if old_link_up != self.link_up {
|
||||||
socket.reset();
|
socket.reset();
|
||||||
}
|
}
|
||||||
match socket.poll() {
|
match socket.poll() {
|
||||||
None => {}
|
None => false,
|
||||||
Some(dhcpv4::Event::Deconfigured) => {
|
Some(dhcpv4::Event::Deconfigured) => {
|
||||||
self.static_v4 = None;
|
self.static_v4 = None;
|
||||||
apply_config = true;
|
true
|
||||||
}
|
}
|
||||||
Some(dhcpv4::Event::Configured(config)) => {
|
Some(dhcpv4::Event::Configured(config)) => {
|
||||||
self.static_v4 = Some(StaticConfigV4 {
|
self.static_v4 = Some(StaticConfigV4 {
|
||||||
@ -854,20 +851,21 @@ impl Inner {
|
|||||||
gateway: config.router,
|
gateway: config.router,
|
||||||
dns_servers: config.dns_servers,
|
dns_servers: config.dns_servers,
|
||||||
});
|
});
|
||||||
apply_config = true;
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if old_link_up {
|
} else if old_link_up {
|
||||||
socket.reset();
|
socket.reset();
|
||||||
self.static_v4 = None;
|
self.static_v4 = None;
|
||||||
apply_config = true;
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
};
|
||||||
|
if configure {
|
||||||
|
self.apply_static_config()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if apply_config {
|
|
||||||
self.apply_static_config();
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(poll_at) = self.iface.poll_at(timestamp, &mut self.sockets) {
|
if let Some(poll_at) = self.iface.poll_at(timestamp, &mut self.sockets) {
|
||||||
let t = pin!(Timer::at(instant_from_smoltcp(poll_at)));
|
let t = pin!(Timer::at(instant_from_smoltcp(poll_at)));
|
||||||
if t.poll(cx).is_ready() {
|
if t.poll(cx).is_ready() {
|
||||||
|
@ -186,7 +186,7 @@ impl<'a> TcpSocket<'a> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
io: TcpIo { stack: stack, handle },
|
io: TcpIo { stack, handle },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -806,7 +806,7 @@ pub mod client {
|
|||||||
};
|
};
|
||||||
let remote_endpoint = (addr, remote.port());
|
let remote_endpoint = (addr, remote.port());
|
||||||
let mut socket = TcpConnection::new(self.stack, self.state)?;
|
let mut socket = TcpConnection::new(self.stack, self.state)?;
|
||||||
socket.socket.set_timeout(self.socket_timeout.clone());
|
socket.socket.set_timeout(self.socket_timeout);
|
||||||
socket
|
socket
|
||||||
.socket
|
.socket
|
||||||
.connect(remote_endpoint)
|
.connect(remote_endpoint)
|
||||||
|
Loading…
Reference in New Issue
Block a user