@@ -15,32 +15,31 @@ use crate::{to_emb_addr, to_emb_bind_socket, to_emb_socket, to_net_socket, Pool}
15
15
/// Capable of managing up to N concurrent connections with TX and RX buffers according to TX_SZ and RX_SZ, and packet metadata according to `M`.
16
16
pub struct Udp <
17
17
' d ,
18
- D : Driver ,
19
18
const N : usize ,
20
19
const TX_SZ : usize = 1500 ,
21
20
const RX_SZ : usize = 1500 ,
22
21
const M : usize = 2 ,
23
22
> {
24
- stack : & ' d Stack < D > ,
23
+ stack : Stack < ' d > ,
25
24
buffers : & ' d UdpBuffers < N , TX_SZ , RX_SZ , M > ,
26
25
}
27
26
28
- impl < ' d , D : Driver , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize >
29
- Udp < ' d , D , N , TX_SZ , RX_SZ , M >
27
+ impl < ' d , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize >
28
+ Udp < ' d , N , TX_SZ , RX_SZ , M >
30
29
{
31
30
/// Create a new `Udp` instance for the provided Embassy networking stack using the provided UDP buffers.
32
- pub fn new ( stack : & ' d Stack < D > , buffers : & ' d UdpBuffers < N , TX_SZ , RX_SZ , M > ) -> Self {
31
+ pub fn new ( stack : Stack < ' d > , buffers : & ' d UdpBuffers < N , TX_SZ , RX_SZ , M > ) -> Self {
33
32
Self { stack, buffers }
34
33
}
35
34
}
36
35
37
- impl < ' d , D : Driver , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize > UdpBind
38
- for Udp < ' d , D , N , TX_SZ , RX_SZ , M >
36
+ impl < ' d , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize > UdpBind
37
+ for Udp < ' d , N , TX_SZ , RX_SZ , M >
39
38
{
40
39
type Error = UdpError ;
41
40
42
41
type Socket < ' a >
43
- = UdpSocket < ' a , D , N , TX_SZ , RX_SZ , M >
42
+ = UdpSocket < ' a , N , TX_SZ , RX_SZ , M >
44
43
where
45
44
Self : ' a ;
46
45
@@ -57,24 +56,23 @@ impl<'d, D: Driver, const N: usize, const TX_SZ: usize, const RX_SZ: usize, cons
57
56
/// Implements the `UdpReceive` `UdpSend` and `UdpSplit` traits from `edge-nal`
58
57
pub struct UdpSocket <
59
58
' d ,
60
- D : Driver ,
61
59
const N : usize ,
62
60
const TX_SZ : usize ,
63
61
const RX_SZ : usize ,
64
62
const M : usize ,
65
63
> {
66
- stack : & ' d embassy_net:: Stack < D > ,
64
+ stack : embassy_net:: Stack < ' d > ,
67
65
socket : embassy_net:: udp:: UdpSocket < ' d > ,
68
66
stack_buffers : & ' d UdpBuffers < N , TX_SZ , RX_SZ , M > ,
69
67
socket_buffers : NonNull < ( [ u8 ; TX_SZ ] , [ u8 ; RX_SZ ] ) > ,
70
68
socket_meta_buffers : NonNull < ( [ PacketMetadata ; M ] , [ PacketMetadata ; M ] ) > ,
71
69
}
72
70
73
- impl < ' d , D : Driver , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize >
74
- UdpSocket < ' d , D , N , TX_SZ , RX_SZ , M >
71
+ impl < ' d , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize >
72
+ UdpSocket < ' d , N , TX_SZ , RX_SZ , M >
75
73
{
76
74
fn new (
77
- stack : & ' d Stack < D > ,
75
+ stack : Stack < ' d > ,
78
76
stack_buffers : & ' d UdpBuffers < N , TX_SZ , RX_SZ , M > ,
79
77
) -> Result < Self , UdpError > {
80
78
let mut socket_buffers = stack_buffers. pool . alloc ( ) . ok_or ( UdpError :: NoBuffers ) ?;
@@ -98,8 +96,8 @@ impl<'d, D: Driver, const N: usize, const TX_SZ: usize, const RX_SZ: usize, cons
98
96
}
99
97
}
100
98
101
- impl < ' d , D : Driver , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize > Drop
102
- for UdpSocket < ' d , D , N , TX_SZ , RX_SZ , M >
99
+ impl < ' d , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize > Drop
100
+ for UdpSocket < ' d , N , TX_SZ , RX_SZ , M >
103
101
{
104
102
fn drop ( & mut self ) {
105
103
unsafe {
@@ -110,24 +108,24 @@ impl<'d, D: Driver, const N: usize, const TX_SZ: usize, const RX_SZ: usize, cons
110
108
}
111
109
}
112
110
113
- impl < ' d , D : Driver , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize >
114
- ErrorType for UdpSocket < ' d , D , N , TX_SZ , RX_SZ , M >
111
+ impl < ' d , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize >
112
+ ErrorType for UdpSocket < ' d , N , TX_SZ , RX_SZ , M >
115
113
{
116
114
type Error = UdpError ;
117
115
}
118
116
119
- impl < ' d , D : Driver , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize >
120
- UdpReceive for UdpSocket < ' d , D , N , TX_SZ , RX_SZ , M >
117
+ impl < ' d , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize >
118
+ UdpReceive for UdpSocket < ' d , N , TX_SZ , RX_SZ , M >
121
119
{
122
120
async fn receive ( & mut self , buffer : & mut [ u8 ] ) -> Result < ( usize , SocketAddr ) , Self :: Error > {
123
121
let ( len, remote_endpoint) = self . socket . recv_from ( buffer) . await ?;
124
122
125
- Ok ( ( len, to_net_socket ( remote_endpoint) ) )
123
+ Ok ( ( len, to_net_socket ( remote_endpoint. endpoint ) ) )
126
124
}
127
125
}
128
126
129
- impl < ' d , D : Driver , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize > UdpSend
130
- for UdpSocket < ' d , D , N , TX_SZ , RX_SZ , M >
127
+ impl < ' d , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize > UdpSend
128
+ for UdpSocket < ' d , N , TX_SZ , RX_SZ , M >
131
129
{
132
130
async fn send ( & mut self , remote : SocketAddr , data : & [ u8 ] ) -> Result < ( ) , Self :: Error > {
133
131
self . socket . send_to ( data, to_emb_socket ( remote) ) . await ?;
@@ -136,24 +134,24 @@ impl<'d, D: Driver, const N: usize, const TX_SZ: usize, const RX_SZ: usize, cons
136
134
}
137
135
}
138
136
139
- impl < ' d , D : Driver , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize >
140
- ErrorType for & UdpSocket < ' d , D , N , TX_SZ , RX_SZ , M >
137
+ impl < ' d , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize >
138
+ ErrorType for & UdpSocket < ' d , N , TX_SZ , RX_SZ , M >
141
139
{
142
140
type Error = UdpError ;
143
141
}
144
142
145
- impl < ' d , D : Driver , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize >
146
- UdpReceive for & UdpSocket < ' d , D , N , TX_SZ , RX_SZ , M >
143
+ impl < ' d , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize >
144
+ UdpReceive for & UdpSocket < ' d , N , TX_SZ , RX_SZ , M >
147
145
{
148
146
async fn receive ( & mut self , buffer : & mut [ u8 ] ) -> Result < ( usize , SocketAddr ) , Self :: Error > {
149
147
let ( len, remote_endpoint) = self . socket . recv_from ( buffer) . await ?;
150
148
151
- Ok ( ( len, to_net_socket ( remote_endpoint) ) )
149
+ Ok ( ( len, to_net_socket ( remote_endpoint. endpoint ) ) )
152
150
}
153
151
}
154
152
155
- impl < ' d , D : Driver , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize > UdpSend
156
- for & UdpSocket < ' d , D , N , TX_SZ , RX_SZ , M >
153
+ impl < ' d , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize > UdpSend
154
+ for & UdpSocket < ' d , N , TX_SZ , RX_SZ , M >
157
155
{
158
156
async fn send ( & mut self , remote : SocketAddr , data : & [ u8 ] ) -> Result < ( ) , Self :: Error > {
159
157
self . socket . send_to ( data, to_emb_socket ( remote) ) . await ?;
@@ -162,16 +160,16 @@ impl<'d, D: Driver, const N: usize, const TX_SZ: usize, const RX_SZ: usize, cons
162
160
}
163
161
}
164
162
165
- impl < ' d , D : Driver , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize > Readable
166
- for & UdpSocket < ' d , D , N , TX_SZ , RX_SZ , M >
163
+ impl < ' d , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize > Readable
164
+ for & UdpSocket < ' d , N , TX_SZ , RX_SZ , M >
167
165
{
168
166
async fn readable ( & mut self ) -> Result < ( ) , Self :: Error > {
169
167
panic ! ( "Not implemented yet" )
170
168
}
171
169
}
172
170
173
- impl < ' d , D : Driver , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize > UdpSplit
174
- for UdpSocket < ' d , D , N , TX_SZ , RX_SZ , M >
171
+ impl < ' d , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize > UdpSplit
172
+ for UdpSocket < ' d , N , TX_SZ , RX_SZ , M >
175
173
{
176
174
type Receive < ' a >
177
175
= & ' a Self
@@ -188,17 +186,16 @@ impl<'d, D: Driver, const N: usize, const TX_SZ: usize, const RX_SZ: usize, cons
188
186
}
189
187
}
190
188
191
- impl < ' d , D : Driver , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize >
192
- MulticastV4 for UdpSocket < ' d , D , N , TX_SZ , RX_SZ , M >
189
+ impl < ' d , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize >
190
+ MulticastV4 for UdpSocket < ' d , N , TX_SZ , RX_SZ , M >
193
191
{
194
192
async fn join_v4 (
195
193
& mut self ,
196
194
multicast_addr : Ipv4Addr ,
197
195
_interface : Ipv4Addr ,
198
196
) -> Result < ( ) , Self :: Error > {
199
197
self . stack
200
- . join_multicast_group ( to_emb_addr ( IpAddr :: V4 ( multicast_addr) ) )
201
- . await ?;
198
+ . join_multicast_group ( to_emb_addr ( IpAddr :: V4 ( multicast_addr) ) ) ?;
202
199
203
200
Ok ( ( ) )
204
201
}
@@ -209,15 +206,14 @@ impl<'d, D: Driver, const N: usize, const TX_SZ: usize, const RX_SZ: usize, cons
209
206
_interface : Ipv4Addr ,
210
207
) -> Result < ( ) , Self :: Error > {
211
208
self . stack
212
- . leave_multicast_group ( to_emb_addr ( IpAddr :: V4 ( multicast_addr) ) )
213
- . await ?;
209
+ . leave_multicast_group ( to_emb_addr ( IpAddr :: V4 ( multicast_addr) ) ) ?;
214
210
215
211
Ok ( ( ) )
216
212
}
217
213
}
218
214
219
- impl < ' d , D : Driver , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize >
220
- MulticastV6 for UdpSocket < ' d , D , N , TX_SZ , RX_SZ , M >
215
+ impl < ' d , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize >
216
+ MulticastV6 for UdpSocket < ' d , N , TX_SZ , RX_SZ , M >
221
217
{
222
218
async fn join_v6 (
223
219
& mut self ,
@@ -236,8 +232,8 @@ impl<'d, D: Driver, const N: usize, const TX_SZ: usize, const RX_SZ: usize, cons
236
232
}
237
233
}
238
234
239
- impl < ' d , D : Driver , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize > Readable
240
- for UdpSocket < ' d , D , N , TX_SZ , RX_SZ , M >
235
+ impl < ' d , const N : usize , const TX_SZ : usize , const RX_SZ : usize , const M : usize > Readable
236
+ for UdpSocket < ' d , N , TX_SZ , RX_SZ , M >
241
237
{
242
238
async fn readable ( & mut self ) -> Result < ( ) , Self :: Error > {
243
239
panic ! ( "Not implemented yet" )
0 commit comments