Skip to content

Commit

Permalink
Merge #573
Browse files Browse the repository at this point in the history
573: Simpler rand r=Dirbaio a=Dirbaio

Requires #571 

Revisits #547, because it turns out the `rand_custom_impl!` macro stuff was less nice than I thought. It's now a simple PRNG owned by Interface. The builder allows setting the random seed.

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
Co-authored-by: Thibaut Vandervelden <thvdveld@vub.be>
Co-authored-by: bors[bot] <26634292+bors[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 4, 2021
2 parents 7d633aa + bc93fbe commit 774b375
Show file tree
Hide file tree
Showing 15 changed files with 726 additions and 697 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
include:
# Test alloc feature which requires nightly.
- rust: nightly
features: alloc rand-custom-impl medium-ethernet proto-ipv4 proto-ipv6 socket-raw socket-udp socket-tcp socket-icmp
features: alloc medium-ethernet proto-ipv4 proto-ipv6 socket-raw socket-udp socket-tcp socket-icmp
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -73,8 +73,8 @@ jobs:

features:
# These feature sets cannot run tests, so we only check they build.
- rand-custom-impl medium-ip medium-ethernet medium-ieee802154 proto-ipv6 proto-ipv6 proto-igmp proto-dhcpv4 socket-raw socket-udp socket-tcp socket-icmp async
- rand-custom-impl defmt medium-ip medium-ethernet proto-ipv6 proto-ipv6 proto-igmp proto-dhcpv4 socket-raw socket-udp socket-tcp socket-icmp async
- medium-ip medium-ethernet medium-ieee802154 proto-ipv6 proto-ipv6 proto-igmp proto-dhcpv4 socket-raw socket-udp socket-tcp socket-icmp async
- defmt medium-ip medium-ethernet proto-ipv6 proto-ipv6 proto-igmp proto-dhcpv4 socket-raw socket-udp socket-tcp socket-icmp async

steps:
- uses: actions/checkout@v2
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ url = "1.0"
std = ["managed/std", "rand_core/std"]
alloc = ["managed/alloc"]
verbose = []
rand-custom-impl = []
"medium-ethernet" = ["socket"]
"medium-ip" = ["socket"]
"medium-ieee802154" = ["socket", "proto-sixlowpan"]
Expand Down
4 changes: 2 additions & 2 deletions examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ fn main() {

let tcp_handle = iface.add_socket(tcp_socket);

let socket = iface.get_socket::<TcpSocket>(tcp_handle);
socket.connect((address, port), 49500).unwrap();
let (socket, cx) = iface.get_socket_and_context::<TcpSocket>(tcp_handle);
socket.connect(cx, (address, port), 49500).unwrap();

let mut tcp_active = false;
loop {
Expand Down
4 changes: 2 additions & 2 deletions examples/httpclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ fn main() {
}
}

let socket = iface.get_socket::<TcpSocket>(tcp_handle);
let (socket, cx) = iface.get_socket_and_context::<TcpSocket>(tcp_handle);

state = match state {
State::Connect if !socket.is_active() => {
debug!("connecting");
let local_port = 49152 + rand::random::<u16>() % 16384;
socket
.connect((address, url.port().unwrap_or(80)), local_port)
.connect(cx, (address, url.port().unwrap_or(80)), local_port)
.unwrap();
State::Request
}
Expand Down
11 changes: 2 additions & 9 deletions examples/loopback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ mod mock {
self.0.get()
}
}

struct Rand;
smoltcp::rand_custom_impl!(Rand);
impl smoltcp::Rand for Rand {
fn rand_bytes(buf: &mut [u8]) {
buf.fill(0x42);
}
}
}

#[cfg(feature = "std")]
Expand Down Expand Up @@ -153,12 +145,13 @@ fn main() {
done = true;
}

let mut socket = iface.get_socket::<TcpSocket>(client_handle);
let (mut socket, cx) = iface.get_socket_and_context::<TcpSocket>(client_handle);
if !socket.is_open() {
if !did_connect {
debug!("connecting");
socket
.connect(
cx,
(IpAddress::v4(127, 0, 0, 1), 1234),
(IpAddress::Unspecified, 65000),
)
Expand Down
Loading

0 comments on commit 774b375

Please sign in to comment.