Skip to content

Commit 38f7526

Browse files
committed
Merge branch 'master' of github.com:smoltcp-rs/smoltcp into pxe_support
2 parents 4bc28ad + 0dfe66b commit 38f7526

32 files changed

+1131
-972
lines changed

.github/workflows/clippy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
on:
22
push:
3-
branches: [ staging, trying, master ]
3+
branches: [ staging, trying ]
44
pull_request_target:
55

66
name: Clippy check

.github/workflows/fuzz.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
on:
22
push:
3-
branches: [ staging, trying, master ]
3+
branches: [ staging, trying ]
44
pull_request:
55

66
name: Fuzz

.github/workflows/rustfmt.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
on:
22
push:
3-
branches: [ staging, trying, master ]
3+
branches: [ staging, trying ]
44
pull_request:
55

66
name: Rustfmt check

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
on:
22
push:
3-
branches: [ staging, trying, master ]
3+
branches: [ staging, trying ]
44
pull_request:
55

66
name: Test
@@ -21,7 +21,7 @@ jobs:
2121
# Failure is permitted on nightly.
2222
rust:
2323
- stable
24-
- 1.53.0
24+
- 1.56.0
2525
- nightly
2626

2727
features:
@@ -68,13 +68,13 @@ jobs:
6868
# Failure is permitted on nightly.
6969
rust:
7070
- stable
71-
- 1.53.0
71+
- 1.56.0
7272
- nightly
7373

7474
features:
7575
# These feature sets cannot run tests, so we only check they build.
7676
- 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
77-
- rand-custom-impl defmt defmt-trace medium-ip medium-ethernet proto-ipv6 proto-ipv6 proto-igmp proto-dhcpv4 socket-raw socket-udp socket-tcp socket-icmp async
77+
- 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
7878

7979
steps:
8080
- uses: actions/checkout@v2

Cargo.toml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ byteorder = { version = "1.0", default-features = false }
2121
log = { version = "0.4.4", default-features = false, optional = true }
2222
libc = { version = "0.2.18", optional = true }
2323
bitflags = { version = "1.0", default-features = false }
24-
defmt = { version = "0.2.0", optional = true }
24+
defmt = { version = "0.3", optional = true }
2525
rand_core = { version = "0.6.3", optional = true, default-features = false }
2626

2727
[dev-dependencies]
@@ -57,12 +57,6 @@ rand-custom-impl = []
5757

5858
"async" = []
5959

60-
defmt-trace = []
61-
defmt-debug = []
62-
defmt-info = []
63-
defmt-warn = []
64-
defmt-error = []
65-
6660
default = [
6761
"std", "log", # needed for `cargo test --no-default-features --features default` :/
6862
"medium-ethernet", "medium-ip", "medium-ieee802154",

examples/benchmark.rs

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use std::thread;
1313

1414
use smoltcp::iface::{InterfaceBuilder, NeighborCache};
1515
use smoltcp::phy::{wait as phy_wait, Device, Medium};
16-
use smoltcp::socket::SocketSet;
1716
use smoltcp::socket::{TcpSocket, TcpSocketBuffer};
1817
use smoltcp::time::{Duration, Instant};
1918
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr};
@@ -97,70 +96,65 @@ fn main() {
9796
let ethernet_addr = EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x01]);
9897
let ip_addrs = [IpCidr::new(IpAddress::v4(192, 168, 69, 1), 24)];
9998
let medium = device.capabilities().medium;
100-
let mut builder = InterfaceBuilder::new(device).ip_addrs(ip_addrs);
99+
let mut builder = InterfaceBuilder::new(device, vec![]).ip_addrs(ip_addrs);
101100
if medium == Medium::Ethernet {
102101
builder = builder
103102
.hardware_addr(ethernet_addr.into())
104103
.neighbor_cache(neighbor_cache);
105104
}
106105
let mut iface = builder.finalize();
107106

108-
let mut sockets = SocketSet::new(vec![]);
109-
let tcp1_handle = sockets.add(tcp1_socket);
110-
let tcp2_handle = sockets.add(tcp2_socket);
107+
let tcp1_handle = iface.add_socket(tcp1_socket);
108+
let tcp2_handle = iface.add_socket(tcp2_socket);
111109
let default_timeout = Some(Duration::from_millis(1000));
112110

113111
let mut processed = 0;
114112
while !CLIENT_DONE.load(Ordering::SeqCst) {
115113
let timestamp = Instant::now();
116-
match iface.poll(&mut sockets, timestamp) {
114+
match iface.poll(timestamp) {
117115
Ok(_) => {}
118116
Err(e) => {
119117
debug!("poll error: {}", e);
120118
}
121119
}
122120

123121
// tcp:1234: emit data
124-
{
125-
let mut socket = sockets.get::<TcpSocket>(tcp1_handle);
126-
if !socket.is_open() {
127-
socket.listen(1234).unwrap();
128-
}
122+
let socket = iface.get_socket::<TcpSocket>(tcp1_handle);
123+
if !socket.is_open() {
124+
socket.listen(1234).unwrap();
125+
}
129126

130-
if socket.can_send() {
131-
if processed < AMOUNT {
132-
let length = socket
133-
.send(|buffer| {
134-
let length = cmp::min(buffer.len(), AMOUNT - processed);
135-
(length, length)
136-
})
137-
.unwrap();
138-
processed += length;
139-
}
127+
if socket.can_send() {
128+
if processed < AMOUNT {
129+
let length = socket
130+
.send(|buffer| {
131+
let length = cmp::min(buffer.len(), AMOUNT - processed);
132+
(length, length)
133+
})
134+
.unwrap();
135+
processed += length;
140136
}
141137
}
142138

143139
// tcp:1235: sink data
144-
{
145-
let mut socket = sockets.get::<TcpSocket>(tcp2_handle);
146-
if !socket.is_open() {
147-
socket.listen(1235).unwrap();
148-
}
140+
let socket = iface.get_socket::<TcpSocket>(tcp2_handle);
141+
if !socket.is_open() {
142+
socket.listen(1235).unwrap();
143+
}
149144

150-
if socket.can_recv() {
151-
if processed < AMOUNT {
152-
let length = socket
153-
.recv(|buffer| {
154-
let length = cmp::min(buffer.len(), AMOUNT - processed);
155-
(length, length)
156-
})
157-
.unwrap();
158-
processed += length;
159-
}
145+
if socket.can_recv() {
146+
if processed < AMOUNT {
147+
let length = socket
148+
.recv(|buffer| {
149+
let length = cmp::min(buffer.len(), AMOUNT - processed);
150+
(length, length)
151+
})
152+
.unwrap();
153+
processed += length;
160154
}
161155
}
162156

163-
match iface.poll_at(&sockets, timestamp) {
157+
match iface.poll_at(timestamp) {
164158
Some(poll_at) if timestamp < poll_at => {
165159
phy_wait(fd, Some(poll_at - timestamp)).expect("wait error");
166160
}

examples/client.rs

Lines changed: 41 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::str::{self, FromStr};
77

88
use smoltcp::iface::{InterfaceBuilder, NeighborCache, Routes};
99
use smoltcp::phy::{wait as phy_wait, Device, Medium};
10-
use smoltcp::socket::{SocketSet, TcpSocket, TcpSocketBuffer};
10+
use smoltcp::socket::{TcpSocket, TcpSocketBuffer};
1111
use smoltcp::time::Instant;
1212
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address};
1313

@@ -42,7 +42,7 @@ fn main() {
4242
routes.add_default_ipv4_route(default_v4_gw).unwrap();
4343

4444
let medium = device.capabilities().medium;
45-
let mut builder = InterfaceBuilder::new(device)
45+
let mut builder = InterfaceBuilder::new(device, vec![])
4646
.ip_addrs(ip_addrs)
4747
.routes(routes);
4848
if medium == Medium::Ethernet {
@@ -52,63 +52,58 @@ fn main() {
5252
}
5353
let mut iface = builder.finalize();
5454

55-
let mut sockets = SocketSet::new(vec![]);
56-
let tcp_handle = sockets.add(tcp_socket);
55+
let tcp_handle = iface.add_socket(tcp_socket);
5756

58-
{
59-
let mut socket = sockets.get::<TcpSocket>(tcp_handle);
60-
socket.connect((address, port), 49500).unwrap();
61-
}
57+
let socket = iface.get_socket::<TcpSocket>(tcp_handle);
58+
socket.connect((address, port), 49500).unwrap();
6259

6360
let mut tcp_active = false;
6461
loop {
6562
let timestamp = Instant::now();
66-
match iface.poll(&mut sockets, timestamp) {
63+
match iface.poll(timestamp) {
6764
Ok(_) => {}
6865
Err(e) => {
6966
debug!("poll error: {}", e);
7067
}
7168
}
7269

73-
{
74-
let mut socket = sockets.get::<TcpSocket>(tcp_handle);
75-
if socket.is_active() && !tcp_active {
76-
debug!("connected");
77-
} else if !socket.is_active() && tcp_active {
78-
debug!("disconnected");
79-
break;
80-
}
81-
tcp_active = socket.is_active();
82-
83-
if socket.may_recv() {
84-
let data = socket
85-
.recv(|data| {
86-
let mut data = data.to_owned();
87-
if !data.is_empty() {
88-
debug!(
89-
"recv data: {:?}",
90-
str::from_utf8(data.as_ref()).unwrap_or("(invalid utf8)")
91-
);
92-
data = data.split(|&b| b == b'\n').collect::<Vec<_>>().concat();
93-
data.reverse();
94-
data.extend(b"\n");
95-
}
96-
(data.len(), data)
97-
})
98-
.unwrap();
99-
if socket.can_send() && !data.is_empty() {
100-
debug!(
101-
"send data: {:?}",
102-
str::from_utf8(data.as_ref()).unwrap_or("(invalid utf8)")
103-
);
104-
socket.send_slice(&data[..]).unwrap();
105-
}
106-
} else if socket.may_send() {
107-
debug!("close");
108-
socket.close();
70+
let socket = iface.get_socket::<TcpSocket>(tcp_handle);
71+
if socket.is_active() && !tcp_active {
72+
debug!("connected");
73+
} else if !socket.is_active() && tcp_active {
74+
debug!("disconnected");
75+
break;
76+
}
77+
tcp_active = socket.is_active();
78+
79+
if socket.may_recv() {
80+
let data = socket
81+
.recv(|data| {
82+
let mut data = data.to_owned();
83+
if !data.is_empty() {
84+
debug!(
85+
"recv data: {:?}",
86+
str::from_utf8(data.as_ref()).unwrap_or("(invalid utf8)")
87+
);
88+
data = data.split(|&b| b == b'\n').collect::<Vec<_>>().concat();
89+
data.reverse();
90+
data.extend(b"\n");
91+
}
92+
(data.len(), data)
93+
})
94+
.unwrap();
95+
if socket.can_send() && !data.is_empty() {
96+
debug!(
97+
"send data: {:?}",
98+
str::from_utf8(data.as_ref()).unwrap_or("(invalid utf8)")
99+
);
100+
socket.send_slice(&data[..]).unwrap();
109101
}
102+
} else if socket.may_send() {
103+
debug!("close");
104+
socket.close();
110105
}
111106

112-
phy_wait(fd, iface.poll_delay(&sockets, timestamp)).expect("wait error");
107+
phy_wait(fd, iface.poll_delay(timestamp)).expect("wait error");
113108
}
114109
}

examples/dhcp_client.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::collections::BTreeMap;
66
use std::os::unix::io::AsRawFd;
77

88
use smoltcp::iface::{Interface, InterfaceBuilder, NeighborCache, Routes};
9-
use smoltcp::socket::{Dhcpv4Event, Dhcpv4Socket, SocketSet};
9+
use smoltcp::socket::{Dhcpv4Event, Dhcpv4Socket};
1010
use smoltcp::time::Instant;
1111
use smoltcp::wire::{EthernetAddress, IpCidr, Ipv4Address, Ipv4Cidr};
1212
use smoltcp::{
@@ -34,7 +34,7 @@ fn main() {
3434
let routes = Routes::new(&mut routes_storage[..]);
3535

3636
let medium = device.capabilities().medium;
37-
let mut builder = InterfaceBuilder::new(device)
37+
let mut builder = InterfaceBuilder::new(device, vec![])
3838
.ip_addrs(ip_addrs)
3939
.routes(routes);
4040
if medium == Medium::Ethernet {
@@ -44,7 +44,6 @@ fn main() {
4444
}
4545
let mut iface = builder.finalize();
4646

47-
let mut sockets = SocketSet::new(vec![]);
4847
let mut dhcp_socket = Dhcpv4Socket::new();
4948

5049
// Set a ridiculously short max lease time to show DHCP renews work properly.
@@ -53,15 +52,16 @@ fn main() {
5352
// IMPORTANT: This should be removed in production.
5453
dhcp_socket.set_max_lease_duration(Some(Duration::from_secs(10)));
5554

56-
let dhcp_handle = sockets.add(dhcp_socket);
55+
let dhcp_handle = iface.add_socket(dhcp_socket);
5756

5857
loop {
5958
let timestamp = Instant::now();
60-
if let Err(e) = iface.poll(&mut sockets, timestamp) {
59+
if let Err(e) = iface.poll(timestamp) {
6160
debug!("poll error: {}", e);
6261
}
6362

64-
match sockets.get::<Dhcpv4Socket>(dhcp_handle).poll() {
63+
let event = iface.get_socket::<Dhcpv4Socket>(dhcp_handle).poll();
64+
match event {
6565
None => {}
6666
Some(Dhcpv4Event::Configured(config)) => {
6767
debug!("DHCP config acquired!");
@@ -90,7 +90,7 @@ fn main() {
9090
}
9191
}
9292

93-
phy_wait(fd, iface.poll_delay(&sockets, timestamp)).expect("wait error");
93+
phy_wait(fd, iface.poll_delay(timestamp)).expect("wait error");
9494
}
9595
}
9696

0 commit comments

Comments
 (0)