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: 3bb3c9e078a9
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: 88b163f63a20
Choose a head ref
  • 3 commits
  • 7 files changed
  • 1 contributor

Commits on Dec 27, 2016

  1. Copy the full SHA
    174bbce View commit details
  2. Add a use_alloc feature.

    whitequark committed Dec 27, 2016
    Copy the full SHA
    72e3427 View commit details
  3. Copy the full SHA
    88b163f View commit details
Showing with 66 additions and 28 deletions.
  1. +4 −3 Cargo.toml
  2. +32 −2 README.md
  3. +2 −2 src/iface/arp_cache.rs
  4. +12 −7 src/lib.rs
  5. +10 −8 src/managed.rs
  6. +5 −5 src/phy/mod.rs
  7. +1 −1 src/phy/tracer.rs
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ libc = { version = "0.2.18", optional = true }
env_logger = "0.3"

[features]
std = ["libc"]
logging = ["log"]
default = ["std", "logging"]
use_std = ["libc"]
use_alloc = []
use_log = ["log"]
default = ["use_std", "use_log"]
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -46,9 +46,13 @@ The UDP protocol is supported over IPv4.
The TCP protocol is supported over IPv4.

* TCP header checksum is supported.
* TCP options are **not** supported. In particular, the MSS of the remote endpoint
is hardcoded at the default value, 536.
* Multiple packets will be transmitted without waiting for an acknowledgement.
* TCP urgent pointer is **not** supported; any urgent octets will be received alongside data.
* Reassembly of out-of-order segments is **not** supported.
* TCP options are **not** supported, in particular:
* Maximum segment size is hardcoded at the default value, 536.
* Window scaling is **not** supported.
* Keepalive is **not** supported.

Installation
------------
@@ -60,6 +64,32 @@ To use the _smoltcp_ library in your project, add the following to `Cargo.toml`:
smoltcp = "0.1"
```

The default configuration assumes a hosted environment, for ease of evaluation.
You probably want to disable default features and configure them one by one:

```toml
[dependencies]
smoltcp = { version = ..., default-features = false, features = [...] }
```

### Feature `use_std`

The `use_std` feature enables use of buffers owned by the networking stack through a dependency
on `std::boxed::Box`. It also enables `smoltcp::phy::RawSocket` and `smoltcp::phy::TapInterface`,
if the platform supports it.

### Feature `use_alloc`

The `use_std` feature enables use of buffers owned by the networking stack through a dependency
on `alloc::boxed::Box`. This only works on nightly rustc.

### Feature `use_log`

The `use_log` feature enables logging of events within the networking stack through
the [log crate][log]. The events are emitted with the TRACE log level.

[log]: https://crates.io/crates/log

Usage example
-------------

4 changes: 2 additions & 2 deletions src/iface/arp_cache.rs
Original file line number Diff line number Diff line change
@@ -67,12 +67,12 @@ impl<'a> SliceCache<'a> {

/// Sort entries in an order suitable for `find`.
fn sort(&mut self) {
#[cfg(feature = "std")]
#[cfg(feature = "use_std")]
fn sort(data: &mut [(IpAddress, EthernetAddress, usize)]) {
data.sort_by_key(|&(key, _, _)| key)
}

#[cfg(not(feature = "std"))]
#[cfg(not(feature = "use_std"))]
fn sort(data: &mut [(IpAddress, EthernetAddress, usize)]) {
// Use an insertion sort, which performs best on 10 elements and less.
for i in 1..data.len() {
19 changes: 12 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
#![feature(associated_consts, const_fn, step_by, intrinsics, slice_patterns)]
#![feature(associated_consts, const_fn, step_by)]
#![cfg_attr(feature = "use_alloc", feature(alloc))]
#![no_std]

extern crate byteorder;

#[cfg(any(test, feature = "std"))]
#[cfg(any(test, feature = "use_std"))]
#[macro_use]
extern crate std;
#[cfg(feature = "std")]
#[cfg(feature = "use_std")]
extern crate libc;
#[cfg(feature = "logging")]
#[cfg(feature = "use_alloc")]
extern crate alloc;
#[cfg(feature = "use_log")]
#[macro_use(trace, log)]
extern crate log;

macro_rules! net_trace {
($($arg:tt)*) => {
#[cfg(feature = "logging")]
trace!($($arg)*)
($($arg:expr),*) => {
#[cfg(feature = "use_log")]
trace!($($arg),*);
#[cfg(not(feature = "use_log"))]
$( let _ = $arg );*; // suppress unused variable warnings
}
}

18 changes: 10 additions & 8 deletions src/managed.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use core::ops::{Deref, DerefMut};
#[cfg(feature = "std")]
#[cfg(any(feature = "use_std", feature = "use_alloc"))]
use core::borrow::BorrowMut;
use core::fmt;

#[cfg(feature = "std")]
#[cfg(feature = "use_std")]
use std::boxed::Box;
#[cfg(feature = "std")]
#[cfg(feature = "use_alloc")]
use alloc::boxed::Box;
#[cfg(feature = "use_std")]
use std::vec::Vec;

/// A managed object.
@@ -26,7 +28,7 @@ pub enum Managed<'a, T: 'a + ?Sized> {
/// Borrowed variant, either a single element or a slice.
Borrowed(&'a mut T),
/// Owned variant, only available with `std` present.
#[cfg(feature = "std")]
#[cfg(any(feature = "use_std", feature = "use_alloc"))]
Owned(Box<BorrowMut<T>>)
}

@@ -42,14 +44,14 @@ impl<'a, T: 'a + ?Sized> From<&'a mut T> for Managed<'a, T> {
}
}

#[cfg(feature = "std")]
#[cfg(any(feature = "use_std", feature = "use_alloc"))]
impl<T, U: BorrowMut<T> + 'static> From<Box<U>> for Managed<'static, T> {
fn from(value: Box<U>) -> Self {
Managed::Owned(value)
}
}

#[cfg(feature = "std")]
#[cfg(feature = "use_std")]
impl<T: 'static> From<Vec<T>> for Managed<'static, [T]> {
fn from(mut value: Vec<T>) -> Self {
value.shrink_to_fit();
@@ -63,7 +65,7 @@ impl<'a, T: 'a + ?Sized> Deref for Managed<'a, T> {
fn deref(&self) -> &Self::Target {
match self {
&Managed::Borrowed(ref value) => value,
#[cfg(feature = "std")]
#[cfg(any(feature = "use_std", feature = "use_alloc"))]
&Managed::Owned(ref value) => (**value).borrow()
}
}
@@ -73,7 +75,7 @@ impl<'a, T: 'a + ?Sized> DerefMut for Managed<'a, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
match self {
&mut Managed::Borrowed(ref mut value) => value,
#[cfg(feature = "std")]
#[cfg(any(feature = "use_std", feature = "use_alloc"))]
&mut Managed::Owned(ref mut value) => (**value).borrow_mut()
}
}
10 changes: 5 additions & 5 deletions src/phy/mod.rs
Original file line number Diff line number Diff line change
@@ -7,19 +7,19 @@
use Error;

#[cfg(feature = "std")]
#[cfg(feature = "use_std")]
mod sys;

mod tracer;
#[cfg(feature = "std")]
#[cfg(feature = "use_std")]
mod raw_socket;
#[cfg(all(feature = "std", target_os = "linux"))]
#[cfg(all(feature = "use_std", target_os = "linux"))]
mod tap_interface;

pub use self::tracer::Tracer;
#[cfg(feature = "std")]
#[cfg(feature = "use_std")]
pub use self::raw_socket::RawSocket;
#[cfg(all(feature = "std", target_os = "linux"))]
#[cfg(all(feature = "use_std", target_os = "linux"))]
pub use self::tap_interface::TapInterface;

/// An interface for sending and receiving raw network frames.
2 changes: 1 addition & 1 deletion src/phy/tracer.rs
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ impl<T: Device, U: PrettyPrint> Tracer<T, U> {
}

/// Create a tracer device, printing to standard output.
#[cfg(feature = "std")]
#[cfg(feature = "use_std")]
pub fn new_stdout(lower: T) -> Tracer<T, U> {
fn writer<U: PrettyPrint>(printer: PrettyPrinter<U>) {
print!("{}", printer)