Selaa lähdekoodia

Add functions to check if the UDP socket buffers are empty or not.

whitequark 8 vuotta sitten
vanhempi
commit
e2b4753173
1 muutettua tiedostoa jossa 10 lisäystä ja 0 poistoa
  1. 10 0
      src/socket/udp.rs

+ 10 - 0
src/socket/udp.rs

@@ -133,6 +133,11 @@ impl<'a, 'b> UdpSocket<'a, 'b> {
         self.endpoint = endpoint.into()
     }
 
+    /// Check whether the transmit buffer is full.
+    pub fn can_send(&self) -> bool {
+        !self.tx_buffer.full()
+    }
+
     /// Enqueue a packet to be sent to a given remote endpoint, and return a pointer
     /// to its payload.
     ///
@@ -155,6 +160,11 @@ impl<'a, 'b> UdpSocket<'a, 'b> {
         Ok(buffer.copy_from_slice(data))
     }
 
+    /// Check whether the receive buffer is full.
+    pub fn can_recv(&self) -> bool {
+        !self.rx_buffer.empty()
+    }
+
     /// Dequeue a packet received from a remote endpoint, and return the endpoint as well
     /// as a pointer to the payload.
     ///