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

View file

@ -50,7 +50,10 @@ impl<SpiBus: ActiveBus, NetworkImpl: Network> W5500<SpiBus, NetworkImpl> {
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
UdpSocket::new(socket)
}