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: 639dfd94c070
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: 5cb2dcd1aad1
Choose a head ref
  • 3 commits
  • 2 files changed
  • 1 contributor

Commits on Aug 25, 2017

  1. README: fix typo.

    whitequark committed Aug 25, 2017
    Copy the full SHA
    81d79c5 View commit details
  2. Copy the full SHA
    b5df506 View commit details
  3. Copy the full SHA
    5cb2dcd View commit details
Showing with 32 additions and 13 deletions.
  1. +1 −1 README.md
  2. +31 −12 src/socket/tcp.rs
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -221,7 +221,7 @@ Read its [source code](/examples/client.rs), then run it as:
cargo run --example client -- tap0 ADDRESS PORT
```

It connects to the given address (not a hostname) and port (e.g. `socat stdio tcp4-listen 1234`),
It connects to the given address (not a hostname) and port (e.g. `socat stdio tcp4-listen:1234`),
and will respond with reversed chunks of the input indefinitely.

### examples/ping.rs
43 changes: 31 additions & 12 deletions src/socket/tcp.rs
Original file line number Diff line number Diff line change
@@ -750,7 +750,7 @@ impl<'a> TcpSocket<'a> {
if self.state == State::Closed { return Err(Error::Rejected) }

let packet = TcpPacket::new_checked(&payload[..ip_repr.payload_len()])?;
let repr = TcpRepr::parse(&packet, &ip_repr.src_addr(), &ip_repr.dst_addr())?;
let mut repr = TcpRepr::parse(&packet, &ip_repr.src_addr(), &ip_repr.dst_addr())?;

// If we're still listening for SYNs and the packet has an ACK, it cannot
// be destined to this socket, but another one may well listen on the same
@@ -901,6 +901,11 @@ impl<'a> TcpSocket<'a> {
}
}

if repr.control == TcpControl::Psh {
// We don't care about the PSH flag.
repr.control = TcpControl::None;
}

// Validate and update the state.
match (self.state, repr) {
// RSTs are not accepted in the LISTEN state.
@@ -1246,8 +1251,10 @@ impl<'a> TcpSocket<'a> {
self.remote_next_seq = repr.seq_number + repr.segment_len();
self.remote_last_ack = repr.ack_number.unwrap_or_default();

if self.remote_next_seq - self.local_seq_no >= self.tx_buffer.len() {
// If we've transmitted all we could, wind up the retransmit timer.
if self.remote_next_seq - self.local_seq_no >= self.tx_buffer.len() &&
repr.segment_len() > 0 {
// If we've transmitted all we could (and there was something to transmit),
// wind up the retransmit timer.
self.timer.set_for_data(timestamp);
}

@@ -1792,11 +1799,9 @@ mod test {
ack_number: Some(REMOTE_SEQ + 1),
..RECV_TEMPL
}]);
recv!(s, time 1000, Err(Error::Exhausted));
assert_eq!(s.state, State::Established);
sanity!(s, TcpSocket {
timer: Timer::Retransmit { expires_at: 100, delay: 100 },
..socket_established()
});
sanity!(s, socket_established());
}

#[test]
@@ -2007,10 +2012,7 @@ mod test {
..RECV_TEMPL
}]);
assert_eq!(s.state, State::CloseWait);
sanity!(s, TcpSocket {
timer: Timer::Retransmit { expires_at: 100, delay: 100 },
..socket_close_wait()
});
sanity!(s, socket_close_wait());
}

#[test]
@@ -2891,7 +2893,7 @@ mod test {
// =========================================================================================//

#[test]
fn test_psh() {
fn test_psh_transmit() {
let mut s = socket_established();
s.remote_win_len = 6;
s.send_slice(b"abcdef").unwrap();
@@ -2911,4 +2913,21 @@ mod test {
..RECV_TEMPL
}), exact);
}

#[test]
fn test_psh_receive() {
let mut s = socket_established();
send!(s, TcpRepr {
control: TcpControl::Psh,
seq_number: REMOTE_SEQ + 1,
ack_number: Some(LOCAL_SEQ + 1),
payload: &b"abcdef"[..],
..SEND_TEMPL
}, Ok(Some(TcpRepr {
seq_number: LOCAL_SEQ + 1,
ack_number: Some(REMOTE_SEQ + 1 + 6),
window_len: 58,
..RECV_TEMPL
})));
}
}