From 6bdeddd201008a8ee027834d03369909f25605f3 Mon Sep 17 00:00:00 2001 From: whitequark Date: Wed, 25 Oct 2017 02:55:01 +0000 Subject: [PATCH] runtime: remove UDP-related code. --- artiq/firmware/runtime/Cargo.toml | 2 +- artiq/firmware/runtime/sched.rs | 74 ------------------------------- 2 files changed, 1 insertion(+), 75 deletions(-) diff --git a/artiq/firmware/runtime/Cargo.toml b/artiq/firmware/runtime/Cargo.toml index f2eaec653..a912ed1cf 100644 --- a/artiq/firmware/runtime/Cargo.toml +++ b/artiq/firmware/runtime/Cargo.toml @@ -39,4 +39,4 @@ features = ["alloc"] git = "https://github.com/m-labs/smoltcp" rev = "f64a99a" default-features = false -features = ["alloc", "log", "proto-udp", "proto-tcp"] +features = ["alloc", "log", "proto-tcp"] diff --git a/artiq/firmware/runtime/sched.rs b/artiq/firmware/runtime/sched.rs index 4b4be6f9e..1a6ce55b4 100644 --- a/artiq/firmware/runtime/sched.rs +++ b/artiq/firmware/runtime/sched.rs @@ -253,80 +253,6 @@ use ::smoltcp::Error as ErrorLower; // https://github.com/rust-lang/rust/issues/44057 // type ErrorLower = ::smoltcp::Error; -type UdpPacketBuffer = ::smoltcp::socket::UdpPacketBuffer<'static>; -type UdpSocketBuffer = ::smoltcp::socket::UdpSocketBuffer<'static, 'static>; -type UdpSocketLower = ::smoltcp::socket::UdpSocket<'static, 'static>; - -pub struct UdpSocket<'a> { - io: &'a Io<'a>, - handle: SocketHandle -} - -impl<'a> UdpSocket<'a> { - pub fn new(io: &'a Io<'a>, buffer_depth: usize, buffer_width: usize) -> UdpSocket<'a> { - let mut rx_buffer = vec![]; - let mut tx_buffer = vec![]; - for _ in 0..buffer_depth { - rx_buffer.push(UdpPacketBuffer::new(vec![0; buffer_width])); - tx_buffer.push(UdpPacketBuffer::new(vec![0; buffer_width])); - } - let handle = borrow_mut!(io.sockets) - .add(UdpSocketLower::new( - UdpSocketBuffer::new(rx_buffer), - UdpSocketBuffer::new(tx_buffer))); - UdpSocket { - io: io, - handle: handle - } - } - - fn with_lower(&self, f: F) -> R - where F: FnOnce(SocketRef) -> R { - let mut sockets = borrow_mut!(self.io.sockets); - let result = f(sockets.get(self.handle)); - result - } - - pub fn bind>(&self, endpoint: T) -> Result<()> { - self.with_lower(|mut s| s.bind(endpoint)) - .map_err(|err| { - match err { - ErrorLower::Illegal => - Error::new(ErrorKind::Other, "already listening"), - ErrorLower::Unaddressable => - Error::new(ErrorKind::AddrNotAvailable, "port cannot be zero"), - _ => unreachable!() - } - }) - } - - pub fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, IpEndpoint)> { - until!(self, UdpSocketLower, |s| s.can_recv())?; - self.with_lower(|mut s| s.recv_slice(buf)) - .map_err(|_| unreachable!()) - } - - pub fn send_to(&self, buf: &[u8], addr: IpEndpoint) -> Result<()> { - until!(self, UdpSocketLower, |s| s.can_send())?; - self.with_lower(|mut s| s.send_slice(buf, addr)) - .map_err(|err| { - match err { - ErrorLower::Unaddressable => - Error::new(ErrorKind::AddrNotAvailable, "unaddressable destination"), - ErrorLower::Truncated => - Error::new(ErrorKind::Other, "packet does not fit in buffer"), - _ => unreachable!() - } - }) - } -} - -impl<'a> Drop for UdpSocket<'a> { - fn drop(&mut self) { - borrow_mut!(self.io.sockets).release(self.handle) - } -} - type TcpSocketBuffer = ::smoltcp::socket::TcpSocketBuffer<'static>; type TcpSocketLower = ::smoltcp::socket::TcpSocket<'static>;