Skip to content

Commit fc69cdb

Browse files
bors[bot]benbrittainthvdveld
authored
Merge #686
686: Changes egress functions to pass up Err(Exhausted) r=thvdveld a=benbrittain Currently the poll functions will return `Ok(true)` instead of `Err(Exhausted)` despite logging about the failed transmission Co-authored-by: Benjamin Brittain <ben@brittain.org> Co-authored-by: Thibaut Vandervelden <thvdveld@vub.be>
2 parents c127421 + 64ce56b commit fc69cdb

File tree

1 file changed

+31
-32
lines changed

1 file changed

+31
-32
lines changed

src/iface/interface.rs

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,14 +1027,20 @@ impl<'a> Interface<'a> {
10271027
#[cfg(feature = "proto-ipv4-fragmentation")]
10281028
match self.ipv4_egress(device) {
10291029
Ok(true) => return Ok(true),
1030-
Err(e) => return Err(e),
1030+
Err(e) => {
1031+
net_debug!("failed to transmit: {}", e);
1032+
return Err(e);
1033+
}
10311034
_ => (),
10321035
}
10331036

10341037
#[cfg(feature = "proto-sixlowpan-fragmentation")]
10351038
match self.sixlowpan_egress(device) {
10361039
Ok(true) => return Ok(true),
1037-
Err(e) => return Err(e),
1040+
Err(e) => {
1041+
net_debug!("failed to transmit: {}", e);
1042+
return Err(e);
1043+
}
10381044
_ => (),
10391045
}
10401046

@@ -1333,6 +1339,11 @@ impl<'a> Interface<'a> {
13331339
}
13341340
}
13351341

1342+
/// Process fragments that still need to be sent for IPv4 packets.
1343+
///
1344+
/// This function returns a boolean value indicating whether any packets were
1345+
/// processed or emitted, and thus, whether the readiness of any socket might
1346+
/// have changed.
13361347
#[cfg(feature = "proto-ipv4-fragmentation")]
13371348
fn ipv4_egress<D>(&mut self, device: &mut D) -> Result<bool>
13381349
where
@@ -1354,25 +1365,23 @@ impl<'a> Interface<'a> {
13541365
} = &self.out_packets.ipv4_out_packet;
13551366

13561367
if *packet_len > *sent_bytes {
1357-
match device.transmit().ok_or(Error::Exhausted) {
1358-
Ok(tx_token) => {
1359-
if let Err(e) = self
1360-
.inner
1361-
.dispatch_ipv4_out_packet(tx_token, &mut self.out_packets.ipv4_out_packet)
1362-
{
1363-
net_debug!("failed to transmit: {}", e);
1364-
}
1365-
}
1366-
Err(e) => {
1367-
net_debug!("failed to transmit: {}", e);
1368-
}
1368+
match device.transmit() {
1369+
Some(tx_token) => self
1370+
.inner
1371+
.dispatch_ipv4_out_packet(tx_token, &mut self.out_packets.ipv4_out_packet),
1372+
None => Err(Error::Exhausted),
13691373
}
1370-
Ok(true)
1374+
.map(|_| true)
13711375
} else {
13721376
Ok(false)
13731377
}
13741378
}
13751379

1380+
/// Process fragments that still need to be sent for 6LoWPAN packets.
1381+
///
1382+
/// This function returns a boolean value indicating whether any packets were
1383+
/// processed or emitted, and thus, whether the readiness of any socket might
1384+
/// have changed.
13761385
#[cfg(feature = "proto-sixlowpan-fragmentation")]
13771386
fn sixlowpan_egress<D>(&mut self, device: &mut D) -> Result<bool>
13781387
where
@@ -1393,25 +1402,15 @@ impl<'a> Interface<'a> {
13931402
..
13941403
} = &self.out_packets.sixlowpan_out_packet;
13951404

1396-
if *packet_len == 0 {
1397-
return Ok(false);
1398-
}
1399-
14001405
if *packet_len > *sent_bytes {
1401-
match device.transmit().ok_or(Error::Exhausted) {
1402-
Ok(tx_token) => {
1403-
if let Err(e) = self.inner.dispatch_ieee802154_out_packet(
1404-
tx_token,
1405-
&mut self.out_packets.sixlowpan_out_packet,
1406-
) {
1407-
net_debug!("failed to transmit: {}", e);
1408-
}
1409-
}
1410-
Err(e) => {
1411-
net_debug!("failed to transmit: {}", e);
1412-
}
1406+
match device.transmit() {
1407+
Some(tx_token) => self.inner.dispatch_ieee802154_out_packet(
1408+
tx_token,
1409+
&mut self.out_packets.sixlowpan_out_packet,
1410+
),
1411+
None => Err(Error::Exhausted),
14131412
}
1414-
Ok(true)
1413+
.map(|_| true)
14151414
} else {
14161415
Ok(false)
14171416
}

0 commit comments

Comments
 (0)