Finished UDP socket init

This commit is contained in:
Jonah Dahlquist 2019-09-05 20:39:21 -05:00 committed by Jonah Dahlquist
commit 36df284dca
5 changed files with 84 additions and 63 deletions

View file

@ -52,12 +52,14 @@ impl<SpiBus: ActiveBus, NetworkImpl: Network> W5500<SpiBus, NetworkImpl> {
pub fn open_udp_socket<'a, SocketImpl: Socket>(
self,
port: u16,
socket: &'a mut SocketImpl,
) -> Result<UdpSocket<'a, SpiBus, NetworkImpl, SocketImpl>, ForeignSocketError> {
) -> Result<UdpSocket<'a, SpiBus, NetworkImpl, SocketImpl>, OpenSocketError<SpiBus::Error>> {
if socket.is_owned_by(&self.sockets) {
Ok(UdpSocket::new(self.bus, self.network, self.sockets, socket))
UdpSocket::new(port, self.bus, self.network, self.sockets, socket)
.map_err(|e| OpenSocketError::BusError(e))
} else {
Err(ForeignSocketError {})
Err(OpenSocketError::ForeignSocketError)
}
}
@ -82,4 +84,9 @@ impl<Spi: FullDuplex<u8>, NetworkImpl: Network> W5500<ActiveThreeWire<Spi>, Netw
}
}
pub enum OpenSocketError<BusError> {
ForeignSocketError,
BusError(BusError),
}
pub struct ForeignSocketError {}