@@ -4,7 +4,7 @@ use crate::interface::Interface;
4
4
use crate :: register:: socketn;
5
5
use crate :: socket:: Socket ;
6
6
use core:: fmt:: Debug ;
7
- use embedded_nal:: { nb, IpAddr , Ipv4Addr , SocketAddr , SocketAddrV4 , UdpClient , UdpServer } ;
7
+ use embedded_nal:: { nb, IpAddr , Ipv4Addr , SocketAddr , SocketAddrV4 , UdpClientStack , UdpFullStack } ;
8
8
9
9
pub struct UdpSocket {
10
10
socket : Socket ,
@@ -178,15 +178,15 @@ impl<E: Debug> From<NbError<E>> for nb::Error<E> {
178
178
}
179
179
}
180
180
181
- impl < SpiBus , HostImpl > UdpClient for Interface < SpiBus , HostImpl >
181
+ impl < SpiBus , HostImpl > UdpClientStack for Interface < SpiBus , HostImpl >
182
182
where
183
183
SpiBus : ActiveBus ,
184
184
HostImpl : Host ,
185
185
{
186
186
type UdpSocket = UdpSocket ;
187
187
type Error = UdpSocketError < SpiBus :: Error > ;
188
188
189
- fn socket ( & self ) -> Result < Self :: UdpSocket , Self :: Error > {
189
+ fn socket ( & mut self ) -> Result < Self :: UdpSocket , Self :: Error > {
190
190
let mut device = self . device . borrow_mut ( ) ;
191
191
if let Some ( socket) = device. take_socket ( ) {
192
192
Ok ( UdpSocket :: new ( socket) )
@@ -195,7 +195,7 @@ where
195
195
}
196
196
}
197
197
198
- fn connect ( & self , socket : & mut Self :: UdpSocket , remote : SocketAddr ) -> Result < ( ) , Self :: Error > {
198
+ fn connect ( & mut self , socket : & mut Self :: UdpSocket , remote : SocketAddr ) -> Result < ( ) , Self :: Error > {
199
199
let mut device = self . device . borrow_mut ( ) ;
200
200
if let SocketAddr :: V4 ( remote) = remote {
201
201
// TODO find a random port
@@ -206,37 +206,37 @@ where
206
206
Err ( Self :: Error :: UnsupportedAddress )
207
207
}
208
208
}
209
- fn send ( & self , socket : & mut Self :: UdpSocket , buffer : & [ u8 ] ) -> nb:: Result < ( ) , Self :: Error > {
209
+ fn send ( & mut self , socket : & mut Self :: UdpSocket , buffer : & [ u8 ] ) -> nb:: Result < ( ) , Self :: Error > {
210
210
socket. send ( & mut self . device . borrow_mut ( ) . bus , buffer) ?;
211
211
Ok ( ( ) )
212
212
}
213
213
fn receive (
214
- & self ,
214
+ & mut self ,
215
215
socket : & mut Self :: UdpSocket ,
216
216
buffer : & mut [ u8 ] ,
217
217
) -> nb:: Result < ( usize , SocketAddr ) , Self :: Error > {
218
218
Ok ( socket. receive ( & mut self . device . borrow_mut ( ) . bus , buffer) ?)
219
219
}
220
- fn close ( & self , socket : Self :: UdpSocket ) -> Result < ( ) , Self :: Error > {
220
+ fn close ( & mut self , socket : Self :: UdpSocket ) -> Result < ( ) , Self :: Error > {
221
221
let mut device = self . device . borrow_mut ( ) ;
222
222
socket. close ( & mut device. bus ) ?;
223
223
device. release_socket ( socket. socket ) ;
224
224
Ok ( ( ) )
225
225
}
226
226
}
227
227
228
- impl < SpiBus , HostImpl > UdpServer for Interface < SpiBus , HostImpl >
228
+ impl < SpiBus , HostImpl > UdpFullStack for Interface < SpiBus , HostImpl >
229
229
where
230
230
SpiBus : ActiveBus ,
231
231
HostImpl : Host ,
232
232
{
233
- fn bind ( & self , socket : & mut Self :: UdpSocket , local_port : u16 ) -> Result < ( ) , Self :: Error > {
233
+ fn bind ( & mut self , socket : & mut Self :: UdpSocket , local_port : u16 ) -> Result < ( ) , Self :: Error > {
234
234
let mut device = self . device . borrow_mut ( ) ;
235
235
socket. open ( & mut device. bus , local_port) ?;
236
236
Ok ( ( ) )
237
237
}
238
238
fn send_to (
239
- & self ,
239
+ & mut self ,
240
240
socket : & mut Self :: UdpSocket ,
241
241
remote : SocketAddr ,
242
242
buffer : & [ u8 ] ,
0 commit comments