Don't panic on TCP sequence number wrapping in debug mode.
This commit is contained in:
parent
1e809daf7a
commit
2a52234d53
|
@ -1482,6 +1482,7 @@ impl<'a> fmt::Write for TcpSocket<'a> {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
use core::i32;
|
||||||
use wire::{IpAddress, IpRepr};
|
use wire::{IpAddress, IpRepr};
|
||||||
use wire::{Ipv4Address, IpCidr, Ipv4Repr};
|
use wire::{Ipv4Address, IpCidr, Ipv4Repr};
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -2128,6 +2129,21 @@ mod test {
|
||||||
}]);
|
}]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_established_send_wrap() {
|
||||||
|
let mut s = socket_established();
|
||||||
|
let local_seq_start = TcpSeqNumber(i32::MAX - 1);
|
||||||
|
s.local_seq_no = local_seq_start + 1;
|
||||||
|
s.remote_last_seq = local_seq_start + 1;
|
||||||
|
s.send_slice(b"abc").unwrap();
|
||||||
|
recv!(s, time 1000, Ok(TcpRepr {
|
||||||
|
seq_number: local_seq_start + 1,
|
||||||
|
ack_number: Some(REMOTE_SEQ + 1),
|
||||||
|
payload: &b"abc"[..],
|
||||||
|
..RECV_TEMPL
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_established_no_ack() {
|
fn test_established_no_ack() {
|
||||||
let mut s = socket_established();
|
let mut s = socket_established();
|
||||||
|
|
|
@ -51,13 +51,13 @@ impl ops::Sub for SeqNumber {
|
||||||
type Output = usize;
|
type Output = usize;
|
||||||
|
|
||||||
fn sub(self, rhs: SeqNumber) -> usize {
|
fn sub(self, rhs: SeqNumber) -> usize {
|
||||||
(self.0 - rhs.0) as usize
|
self.0.wrapping_sub(rhs.0) as usize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl cmp::PartialOrd for SeqNumber {
|
impl cmp::PartialOrd for SeqNumber {
|
||||||
fn partial_cmp(&self, other: &SeqNumber) -> Option<cmp::Ordering> {
|
fn partial_cmp(&self, other: &SeqNumber) -> Option<cmp::Ordering> {
|
||||||
(self.0 - other.0).partial_cmp(&0)
|
self.0.wrapping_sub(other.0).partial_cmp(&0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue