Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: smoltcp-rs/smoltcp
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5f3296c5c570
Choose a base ref
...
head repository: smoltcp-rs/smoltcp
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 53feb670e716
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Jan 25, 2017

  1. Copy the full SHA
    4d11b52 View commit details
  2. Copy the full SHA
    53feb67 View commit details
Showing with 59 additions and 15 deletions.
  1. +59 −15 src/socket/tcp.rs
74 changes: 59 additions & 15 deletions src/socket/tcp.rs
Original file line number Diff line number Diff line change
@@ -630,14 +630,6 @@ impl<'a> TcpSocket<'a> {
ack_number, self.local_seq_no, self.local_seq_no + unacknowledged);
return Err(Error::Dropped)
}
// If we got a valid acknowledgement and the transmit half of the connection
// is open, reset the retransmit timer.
// This primarily matters in the case where the local endpoint keeps sending data
// already in its buffer (e.g. if the contents of the buffer exceed the window
// of the remote endpoint), and nothing else happens.
if self.may_send() {
self.retransmit.reset()
}
}
}

@@ -715,8 +707,10 @@ impl<'a> TcpSocket<'a> {
self.retransmit.reset();
}

// ACK packets in ESTABLISHED state do nothing.
(State::Established, TcpRepr { control: TcpControl::None, .. }) => (),
// ACK packets in ESTABLISHED state reset the retransmit timer.
(State::Established, TcpRepr { control: TcpControl::None, .. }) => {
self.retransmit.reset()
},

// FIN packets in ESTABLISHED state indicate the remote side has closed.
(State::Established, TcpRepr { control: TcpControl::Fin, .. }) => {
@@ -725,9 +719,12 @@ impl<'a> TcpSocket<'a> {
self.retransmit.reset();
}

// ACK packets in FIN-WAIT-1 state change it to FIN-WAIT-2.
// ACK packets in FIN-WAIT-1 state change it to FIN-WAIT-2, if we've already
// sent everything in the transmit buffer.
(State::FinWait1, TcpRepr { control: TcpControl::None, .. }) => {
self.set_state(State::FinWait2);
if self.tx_buffer.empty() {
self.set_state(State::FinWait2);
}
}

// FIN packets in FIN-WAIT-1 state change it to CLOSING.
@@ -750,8 +747,10 @@ impl<'a> TcpSocket<'a> {
self.retransmit.reset();
}

// ACK packets in CLOSE-WAIT state do nothing.
(State::CloseWait, TcpRepr { control: TcpControl::None, .. }) => (),
// ACK packets in CLOSE-WAIT state reset the retransmit timer.
(State::CloseWait, TcpRepr { control: TcpControl::None, .. }) => {
self.retransmit.reset();
}

// ACK packets in LAST-ACK state change it to CLOSED.
(State::LastAck, TcpRepr { control: TcpControl::None, .. }) => {
@@ -1654,6 +1653,12 @@ mod test {
payload: &b"abcdef"[..],
..RECV_TEMPL
}]);
send!(s, TcpRepr {
seq_number: REMOTE_SEQ + 1,
ack_number: Some(LOCAL_SEQ + 1 + 6),
..SEND_TEMPL
});
assert_eq!(s.state, State::FinWait1);
}

#[test]
@@ -2115,7 +2120,7 @@ mod test {
}

#[test]
fn test_retransmit_reset_after_ack() {
fn test_established_retransmit_reset_after_ack() {
let mut s = socket_established();
s.remote_win_len = 6;
s.send_slice(b"abcdef").unwrap();
@@ -2152,4 +2157,43 @@ mod test {
..RECV_TEMPL
}));
}

#[test]
fn test_close_wait_retransmit_reset_after_ack() {
let mut s = socket_close_wait();
s.remote_win_len = 6;
s.send_slice(b"abcdef").unwrap();
s.send_slice(b"123456").unwrap();
s.send_slice(b"ABCDEF").unwrap();
recv!(s, time 1000, Ok(TcpRepr {
seq_number: LOCAL_SEQ + 1,
ack_number: Some(REMOTE_SEQ + 1 + 1),
payload: &b"abcdef"[..],
..RECV_TEMPL
}));
send!(s, time 1005, TcpRepr {
seq_number: REMOTE_SEQ + 1 + 1,
ack_number: Some(LOCAL_SEQ + 1 + 6),
window_len: 6,
..SEND_TEMPL
});
recv!(s, time 1010, Ok(TcpRepr {
seq_number: LOCAL_SEQ + 1 + 6,
ack_number: Some(REMOTE_SEQ + 1 + 1),
payload: &b"123456"[..],
..RECV_TEMPL
}));
send!(s, time 1015, TcpRepr {
seq_number: REMOTE_SEQ + 1 + 1,
ack_number: Some(LOCAL_SEQ + 1 + 6 + 6),
window_len: 6,
..SEND_TEMPL
});
recv!(s, time 1020, Ok(TcpRepr {
seq_number: LOCAL_SEQ + 1 + 6 + 6,
ack_number: Some(REMOTE_SEQ + 1 + 1),
payload: &b"ABCDEF"[..],
..RECV_TEMPL
}));
}
}