Skip to content

Commit

Permalink
Add SO_REUSEADDR support
Browse files Browse the repository at this point in the history
  • Loading branch information
YXalix committed Apr 27, 2024
1 parent 125773e commit 4c77438
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/iface/interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ impl Interface {
let mut processed_any = false;

while let Some((rx_token, tx_token)) = device.receive(self.inner.now) {
rx_token.preprocess(sockets);
let rx_meta = rx_token.meta();
rx_token.consume(|frame| {
if frame.is_empty() {
Expand Down
14 changes: 10 additions & 4 deletions src/iface/interface/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ impl InterfaceInner {
));

#[cfg(feature = "socket-udp")]
for udp_socket in sockets
{
let mut is_received = false;
for udp_socket in sockets
.items_mut()
.filter_map(|i| UdpSocket::downcast_mut(&mut i.socket))
{
if udp_socket.accepts(self, &ip_repr, &udp_repr) {
udp_socket.process(self, meta, &ip_repr, &udp_repr, udp_packet.payload());
{
if udp_socket.accepts(self, &ip_repr, &udp_repr) {
udp_socket.process(self, meta, &ip_repr, &udp_repr, udp_packet.payload());
is_received = true;
}
}
if is_received {
return None;
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/phy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ impl<'a> phy::TxToken for StmPhyTxToken<'a> {
"##
)]

use crate::iface::SocketSet;
use crate::time::Instant;

#[cfg(all(
Expand Down Expand Up @@ -378,6 +379,11 @@ pub trait RxToken {
fn meta(&self) -> PacketMeta {
PacketMeta::default()
}

/// Preprocess the incomming packet before it is passed to the stack.
///
/// e.g., prepare TCP sockets when received a SYN packet.
fn preprocess(&self, _sockets: &mut SocketSet<'_>) {}
}

/// A token to transmit a single network packet.
Expand Down

0 comments on commit 4c77438

Please sign in to comment.