Changed UdpSocket to store a socket reference

This commit is contained in:
Jonah Dahlquist 2019-08-13 20:26:02 -05:00 committed by Jonah Dahlquist
commit 715cdea318
2 changed files with 11 additions and 8 deletions

View file

@ -1,12 +1,12 @@
use crate::socket::Socket; use crate::socket::Socket;
pub struct UdpSocket<SocketImpl: Socket> { pub struct UdpSocket<'a, SocketImpl: Socket> {
socket: SocketImpl, socket: &'a mut SocketImpl,
} }
impl<SocketImpl: Socket> UdpSocket<SocketImpl> { impl<'a, SocketImpl: Socket> UdpSocket<'a, SocketImpl> {
pub fn new(socket: SocketImpl) -> Self { pub fn new(socket: &'a mut SocketImpl) -> Self {
// TODO initialize socket for UDP mode // TODO initialize socket for UDP mode
UdpSocket { socket } UdpSocket { socket }
} }
} }

View file

@ -50,7 +50,10 @@ impl<SpiBus: ActiveBus, NetworkImpl: Network> W5500<SpiBus, NetworkImpl> {
Ok(()) Ok(())
} }
pub fn open_udp_socket<SocketImpl: Socket>(&self, socket: SocketImpl) -> UdpSocket<SocketImpl> { pub fn open_udp_socket<'a, SocketImpl: Socket>(
&self,
socket: &'a mut SocketImpl,
) -> UdpSocket<'a, SocketImpl> {
// TODO compare socket to sockets list // TODO compare socket to sockets list
UdpSocket::new(socket) UdpSocket::new(socket)
} }