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: ee20c49a5987
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: 908f70957b33
Choose a head ref
  • 3 commits
  • 6 files changed
  • 1 contributor

Commits on Mar 5, 2017

  1. Don't block forever in TapInterface.

    Ideally Devices should be non-blocking, but that would be really
    annoying to implement, so for now, to get the examples working,
    I'm using this hack.
    whitequark committed Mar 5, 2017
    Copy the full SHA
    be9d0a2 View commit details
  2. Copy the full SHA
    708f40d View commit details
  3. Travis: don't build tests without the std feature.

    Neither tests nor examples work without the library being built
    with std.
    whitequark committed Mar 5, 2017
    Copy the full SHA
    908f709 View commit details
Showing with 49 additions and 15 deletions.
  1. +7 −7 .travis.yml
  2. +3 −1 examples/client.rs
  3. +2 −1 examples/server.rs
  4. +25 −1 src/phy/sys/tap_interface.rs
  5. +10 −3 src/phy/tap_interface.rs
  6. +2 −2 src/socket/tcp.rs
14 changes: 7 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -2,21 +2,21 @@ language: rust
matrix:
include:
- rust: stable
env: FEATURES='use_std'
env: FEATURES='use_std' MODE='test'
- rust: beta
env: FEATURES='use_std'
env: FEATURES='use_std' MODE='test'
- rust: nightly
env: FEATURES='use_std'
env: FEATURES='use_std' MODE='test'
- rust: nightly
env: FEATURES='use_std use_log'
env: FEATURES='use_std use_log' MODE='test'
- rust: nightly
env: FEATURES='use_alloc use_collections'
env: FEATURES='use_alloc use_collections' MODE='build'
- rust: nightly
env: FEATURES=''
env: FEATURES='' MODE='build'
allow_failures:
- rust: stable # until 1.15 comes out
script:
- cargo test --no-default-features --features "$FEATURES"
- cargo "$MODE" --no-default-features --features "$FEATURES"
notifications:
irc:
channels:
4 changes: 3 additions & 1 deletion examples/client.rs
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ mod utils;

use std::str::{self, FromStr};
use std::time::Instant;
use smoltcp::Error;
use smoltcp::wire::{EthernetAddress, IpAddress};
use smoltcp::iface::{ArpCache, SliceArpCache, EthernetInterface};
use smoltcp::socket::{AsSocket, SocketSet};
@@ -49,6 +50,7 @@ fn main() {
debug!("connected");
} else if !socket.is_active() && tcp_active {
debug!("disconnected");
break
}
tcp_active = socket.is_active();

@@ -79,7 +81,7 @@ fn main() {
let timestamp_ms = (timestamp.as_secs() * 1000) +
(timestamp.subsec_nanos() / 1000000) as u64;
match iface.poll(&mut sockets, timestamp_ms) {
Ok(()) => (),
Ok(()) | Err(Error::Exhausted) => (),
Err(e) => debug!("poll error: {}", e)
}
}
3 changes: 2 additions & 1 deletion examples/server.rs
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ mod utils;

use std::str;
use std::time::Instant;
use smoltcp::Error;
use smoltcp::wire::{EthernetAddress, IpAddress};
use smoltcp::iface::{ArpCache, SliceArpCache, EthernetInterface};
use smoltcp::socket::{AsSocket, SocketSet};
@@ -128,7 +129,7 @@ fn main() {
let timestamp_ms = (timestamp.as_secs() * 1000) +
(timestamp.subsec_nanos() / 1000000) as u64;
match iface.poll(&mut sockets, timestamp_ms) {
Ok(()) => (),
Ok(()) | Err(Error::Exhausted) => (),
Err(e) => debug!("poll error: {}", e)
}
}
26 changes: 25 additions & 1 deletion src/phy/sys/tap_interface.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use libc;
use std::mem;
use std::io;
use libc;
use super::*;

#[cfg(target_os = "linux")]
@@ -29,7 +30,28 @@ impl TapInterfaceDesc {
ifreq_ioctl(self.lower, &mut self.ifreq, imp::TUNSETIFF).map(|_| ())
}

fn wait(&mut self, ms: u32) -> io::Result<bool> {
unsafe {
let mut readfds = mem::uninitialized::<libc::fd_set>();
libc::FD_ZERO(&mut readfds);
libc::FD_SET(self.lower, &mut readfds);
let mut writefds = mem::uninitialized::<libc::fd_set>();
libc::FD_ZERO(&mut writefds);
let mut exceptfds = mem::uninitialized::<libc::fd_set>();
libc::FD_ZERO(&mut exceptfds);
let mut timeout = libc::timeval { tv_sec: 0, tv_usec: (ms * 1_000) as i64 };
let res = libc::select(self.lower + 1, &mut readfds, &mut writefds, &mut exceptfds,
&mut timeout);
if res == -1 { return Err(io::Error::last_os_error()) }
Ok(res == 0)
}
}

pub fn recv(&mut self, buffer: &mut [u8]) -> io::Result<usize> {
// FIXME: here we don't wait forever, in case we need to send several packets in a row
// ideally this would be implemented by going full nonblocking
if self.wait(100)? { return Err(io::ErrorKind::TimedOut)? }

unsafe {
let len = libc::read(self.lower, buffer.as_mut_ptr() as *mut libc::c_void,
buffer.len());
@@ -39,6 +61,8 @@ impl TapInterfaceDesc {
}

pub fn send(&mut self, buffer: &[u8]) -> io::Result<usize> {
self.wait(100)?;

unsafe {
let len = libc::write(self.lower, buffer.as_ptr() as *const libc::c_void,
buffer.len());
13 changes: 10 additions & 3 deletions src/phy/tap_interface.rs
Original file line number Diff line number Diff line change
@@ -38,9 +38,16 @@ impl Device for TapInterface {
fn receive(&mut self) -> Result<Self::RxBuffer, Error> {
let mut lower = self.lower.borrow_mut();
let mut buffer = vec![0; self.mtu];
let size = lower.recv(&mut buffer[..]).unwrap();
buffer.resize(size, 0);
Ok(buffer)
match lower.recv(&mut buffer[..]) {
Ok(size) => {
buffer.resize(size, 0);
Ok(buffer)
}
Err(ref err) if err.kind() == io::ErrorKind::TimedOut => {
Err(Error::Exhausted)
}
Err(err) => panic!(err)
}
}

fn transmit(&mut self, length: usize) -> Result<Self::TxBuffer, Error> {
4 changes: 2 additions & 2 deletions src/socket/tcp.rs
Original file line number Diff line number Diff line change
@@ -674,7 +674,7 @@ impl<'a> TcpSocket<'a> {
(State::SynSent, TcpRepr {
control: TcpControl::Rst, ack_number: Some(ack_number), ..
}) => {
if ack_number != self.local_seq_no {
if ack_number != self.local_seq_no + 1 {
net_trace!("[{}]{}:{}: unacceptable RST|ACK in response to initial SYN",
self.debug_id, self.local_endpoint, self.remote_endpoint);
return Err(Error::Malformed)
@@ -1501,7 +1501,7 @@ mod test {
send!(s, TcpRepr {
control: TcpControl::Rst,
seq_number: REMOTE_SEQ,
ack_number: Some(LOCAL_SEQ),
ack_number: Some(LOCAL_SEQ + 1),
..SEND_TEMPL
});
assert_eq!(s.state, State::Closed);