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: 0904645c1ba8
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: b971d91315a7
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Jul 23, 2017

  1. Copy the full SHA
    abb0c11 View commit details
  2. Copy the full SHA
    b971d91 View commit details
Showing with 47 additions and 12 deletions.
  1. +13 −11 examples/loopback.rs
  2. +34 −1 src/socket/tcp.rs
24 changes: 13 additions & 11 deletions examples/loopback.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(unused_mut)]

#[cfg(feature = "std")]
use std as core;
#[macro_use]
extern crate log;
extern crate smoltcp;
@@ -13,9 +15,9 @@ extern crate getopts;
#[allow(dead_code)]
mod utils;

use core::str;
use smoltcp::Error;
use smoltcp::phy::Loopback;
use smoltcp::phy::EthernetTracer;
use smoltcp::wire::{EthernetAddress, IpAddress};
use smoltcp::iface::{ArpCache, SliceArpCache, EthernetInterface};
use smoltcp::socket::{AsSocket, SocketSet};
@@ -69,18 +71,13 @@ mod mock {

fn main() {
let clock = mock::Clock::new();
let mut device = Loopback::new();

#[cfg(feature = "std")]
{
let mut device = {
let clock = clock.clone();
utils::setup_logging_with_clock("", move || clock.elapsed());
}

let mut device = Loopback::new();
let mut device = EthernetTracer::new(device, |_timestamp, printer| trace!("{}", printer));

#[cfg(feature = "std")]
let mut device = {
let (mut opts, mut free) = utils::create_options();
utils::add_middleware_options(&mut opts, &mut free);

@@ -132,13 +129,14 @@ fn main() {
let socket: &mut TcpSocket = socket_set.get_mut(server_handle).as_socket();
if !socket.is_active() && !socket.is_listening() {
if !did_listen {
debug!("listening");
socket.listen(1234).unwrap();
did_listen = true;
}
}

if socket.can_recv() {
debug!("got {:?}", socket.recv(32).unwrap());
debug!("got {:?}", str::from_utf8(socket.recv(32).unwrap()).unwrap());
socket.close();
done = true;
}
@@ -148,13 +146,15 @@ fn main() {
let socket: &mut TcpSocket = socket_set.get_mut(client_handle).as_socket();
if !socket.is_open() {
if !did_connect {
debug!("connecting");
socket.connect((IpAddress::v4(127, 0, 0, 1), 1234),
(IpAddress::Unspecified, 65000)).unwrap();
did_connect = true;
}
}

if socket.can_send() {
debug!("sending");
socket.send_slice(b"0123456789abcdef").unwrap();
socket.close();
}
@@ -168,7 +168,9 @@ fn main() {
clock.advance(1);
}

if !done {
error!("this is taking too long, bailing out");
if done {
info!("done")
} else {
error!("this is taking too long, bailing out")
}
}
35 changes: 34 additions & 1 deletion src/socket/tcp.rs
Original file line number Diff line number Diff line change
@@ -852,6 +852,15 @@ impl<'a> TcpSocket<'a> {
self.retransmit.reset();
}

// FIN packets in the SYN-RECEIVED state change it to CLOSE-WAIT.
// It's not obvious from RFC 793 that this is permitted, but
// 7th and 8th steps in the "SEGMENT ARRIVES" event describe this behavior.
(State::SynReceived, TcpRepr { control: TcpControl::Fin, .. }) => {
self.remote_seq_no += 1;
self.set_state(State::CloseWait);
self.retransmit.reset();
}

// SYN|ACK packets in the SYN-SENT state change it to ESTABLISHED.
(State::SynSent, TcpRepr {
control: TcpControl::Syn, seq_number, ack_number: Some(_),
@@ -1498,7 +1507,7 @@ mod test {
}

#[test]
fn test_syn_received_syn_ack() {
fn test_syn_received_ack() {
let mut s = socket_syn_received();
recv!(s, [TcpRepr {
control: TcpControl::Syn,
@@ -1516,6 +1525,30 @@ mod test {
sanity!(s, socket_established());
}

#[test]
fn test_syn_received_fin() {
let mut s = socket_syn_received();
recv!(s, [TcpRepr {
control: TcpControl::Syn,
seq_number: LOCAL_SEQ,
ack_number: Some(REMOTE_SEQ + 1),
max_seg_size: Some(1480),
..RECV_TEMPL
}]);
send!(s, TcpRepr {
control: TcpControl::Fin,
seq_number: REMOTE_SEQ + 1,
ack_number: Some(LOCAL_SEQ + 1),
payload: &b"abcdef"[..],
..SEND_TEMPL
});
assert_eq!(s.state, State::CloseWait);
sanity!(s, TcpSocket {
remote_last_ack: REMOTE_SEQ + 1,
..socket_close_wait()
});
}

#[test]
fn test_syn_received_rst() {
let mut s = socket_syn_received();