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: c73721aa03e2
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: 6f5ae3350182
Choose a head ref
  • 3 commits
  • 5 files changed
  • 1 contributor

Commits on Sep 24, 2017

  1. A few cosmetic changes to TCP socket trace messages.

    No functional change.
    whitequark committed Sep 24, 2017
    Copy the full SHA
    7362e1a View commit details
  2. Copy the full SHA
    b7b4877 View commit details
  3. Copy the full SHA
    6f5ae33 View commit details
Showing with 32 additions and 31 deletions.
  1. +2 −1 README.md
  2. +1 −1 examples/client.rs
  3. +1 −6 examples/ping.rs
  4. +4 −2 examples/server.rs
  5. +24 −21 src/socket/tcp.rs
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -206,7 +206,8 @@ It responds to:
* TCP connections on port 6970 (`socat stdio tcp4-connect:192.168.69.1:6970 <<<"abcdefg"`),
where it will respond with reversed chunks of the input indefinitely.
* TCP connections on port 6971 (`socat stdio tcp4-connect:192.168.69.1:6971 </dev/urandom`),
which will sink data.
which will sink data. Also, keep-alive packets (every 1 s) and a user timeout (at 2 s)
are enabled on this port; try to trigger them using fault injection.
* TCP connections on port 6972 (`socat stdio tcp4-connect:192.168.69.1:6972 >/dev/null`),
which will source data.

2 changes: 1 addition & 1 deletion examples/client.rs
Original file line number Diff line number Diff line change
@@ -90,6 +90,6 @@ fn main() {

let timestamp = utils::millis_since(startup_time);
let poll_at = iface.poll(&mut sockets, timestamp).expect("poll error");
phy_wait(fd, poll_at).expect("wait error");
phy_wait(fd, poll_at.map(|at| at.saturating_sub(timestamp))).expect("wait error");
}
}
7 changes: 1 addition & 6 deletions examples/ping.rs
Original file line number Diff line number Diff line change
@@ -147,12 +147,7 @@ fn main() {
let timestamp = utils::millis_since(startup_time);

let poll_at = iface.poll(&mut sockets, timestamp).expect("poll error");
let mut resume_at = Some(send_at);
if let Some(poll_at) = poll_at {
resume_at = resume_at.map(|at| cmp::min(at, poll_at))
}

debug!("waiting until {:?} ms", resume_at);
let resume_at = [poll_at, Some(send_at)].iter().flat_map(|x| *x).min();
phy_wait(fd, resume_at.map(|at| at.saturating_sub(timestamp))).expect("wait error");
}

6 changes: 4 additions & 2 deletions examples/server.rs
Original file line number Diff line number Diff line change
@@ -147,7 +147,9 @@ fn main() {
{
let socket: &mut TcpSocket = sockets.get_mut(tcp3_handle).as_socket();
if !socket.is_open() {
socket.listen(6971).unwrap()
socket.listen(6971).unwrap();
socket.set_keep_alive(Some(1000));
socket.set_timeout(Some(2000));
}

if socket.may_recv() {
@@ -182,6 +184,6 @@ fn main() {

let timestamp = utils::millis_since(startup_time);
let poll_at = iface.poll(&mut sockets, timestamp).expect("poll error");
phy_wait(fd, poll_at).expect("wait error");
phy_wait(fd, poll_at.map(|at| at.saturating_sub(timestamp))).expect("wait error");
}
}
45 changes: 24 additions & 21 deletions src/socket/tcp.rs
Original file line number Diff line number Diff line change
@@ -1104,7 +1104,7 @@ impl<'a> TcpSocket<'a> {
Ok(()) => {
debug_assert!(self.assembler.total_size() == self.rx_buffer.capacity());
// Place payload octets into the buffer.
net_trace!("[{}]{}:{}: rx buffer: writing {} octets at offset {}",
net_trace!("[{}]{}:{}: rx buffer: receiving {} octets at offset {}",
self.debug_id, self.local_endpoint, self.remote_endpoint,
payload_len, payload_offset);
self.rx_buffer.write_unallocated(payload_offset, repr.payload);
@@ -1292,7 +1292,7 @@ impl<'a> TcpSocket<'a> {
match self.state {
State::FinWait1 | State::LastAck =>
repr.control = TcpControl::Fin,
State::Established | State::CloseWait =>
State::Established | State::CloseWait if repr.payload.len() > 0 =>
repr.control = TcpControl::Psh,
_ => ()
}
@@ -1318,11 +1318,29 @@ impl<'a> TcpSocket<'a> {
}
}

if repr.payload.len() > 0 {
net_trace!("[{}]{}:{}: tx buffer: reading {} octets at offset {}",
// There might be more than one reason to send a packet. E.g. the keep-alive timer
// has expired, and we also have data in transmit buffer. Since any packet that occupies
// sequence space will elicit an ACK, we only need to send an explicit packet if we
// couldn't fill the sequence space with anything.
let is_keep_alive;
if self.timer.should_keep_alive(timestamp) && repr.is_empty() {
repr.seq_number = repr.seq_number - 1;
repr.payload = b"\x00"; // RFC 1122 says we should do this
is_keep_alive = true;
} else {
is_keep_alive = false;
}

// Trace a summary of what will be sent.
if is_keep_alive {
net_trace!("[{}]{}:{}: sending a keep-alive",
self.debug_id, self.local_endpoint, self.remote_endpoint);
} else if repr.payload.len() > 0 {
net_trace!("[{}]{}:{}: tx buffer: sending {} octets at offset {}",
self.debug_id, self.local_endpoint, self.remote_endpoint,
repr.payload.len(), self.remote_last_seq - self.local_seq_no);
} else {
}
if repr.control != TcpControl::None || repr.payload.len() == 0 {
let flags =
match (repr.control, repr.ack_number) {
(TcpControl::Syn, None) => "SYN",
@@ -1331,28 +1349,13 @@ impl<'a> TcpSocket<'a> {
(TcpControl::Rst, Some(_)) => "RST|ACK",
(TcpControl::Psh, Some(_)) => "PSH|ACK",
(TcpControl::None, Some(_)) => "ACK",
_ => unreachable!()
_ => "<unreachable>"
};
net_trace!("[{}]{}:{}: sending {}",
self.debug_id, self.local_endpoint, self.remote_endpoint,
flags);
}

// There might be more than one reason to send a packet. E.g. the keep-alive timer
// has expired, and we also have data in transmit buffer. Since any packet that occupies
// sequence space will elicit an ACK, we only need to send an explicit packet if we
// couldn't fill the sequence space with anything.
let is_keep_alive;
if self.timer.should_keep_alive(timestamp) && repr.is_empty() {
net_trace!("[{}]{}:{}: sending a keep-alive",
self.debug_id, self.local_endpoint, self.remote_endpoint);
repr.seq_number = repr.seq_number - 1;
repr.payload = b"\x00"; // RFC 1122 says we should do this
is_keep_alive = true;
} else {
is_keep_alive = false;
}

if repr.control == TcpControl::Syn {
// Fill the MSS option. See RFC 6691 for an explanation of this calculation.
let mut max_segment_size = limits.max_transmission_unit;