Updating UDP close to clear RX/TX buffers
This commit is contained in:
parent
108543a2f6
commit
fa77ddd836
|
@ -148,7 +148,18 @@ impl<'a> UdpSocket<'a> {
|
||||||
|
|
||||||
/// Close the socket.
|
/// Close the socket.
|
||||||
pub fn close(&mut self) {
|
pub fn close(&mut self) {
|
||||||
|
// Clear the bound endpoint of the socket.
|
||||||
self.endpoint = IpEndpoint::default();
|
self.endpoint = IpEndpoint::default();
|
||||||
|
|
||||||
|
// Reset the RX and TX buffers of the socket.
|
||||||
|
self.tx_buffer.reset();
|
||||||
|
self.rx_buffer.reset();
|
||||||
|
|
||||||
|
#[cfg(feature = "async")]
|
||||||
|
{
|
||||||
|
self.rx_waker.wake();
|
||||||
|
self.tx_waker.wake();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check whether the socket is open.
|
/// Check whether the socket is open.
|
||||||
|
|
|
@ -179,6 +179,12 @@ impl<'a, H> PacketBuffer<'a, H> {
|
||||||
pub fn payload_capacity(&self) -> usize {
|
pub fn payload_capacity(&self) -> usize {
|
||||||
self.payload_ring.capacity()
|
self.payload_ring.capacity()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Reset the packet buffer and clear any staged.
|
||||||
|
pub(crate) fn reset(&mut self) {
|
||||||
|
self.payload_ring.clear();
|
||||||
|
self.metadata_ring.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -304,4 +310,18 @@ mod test {
|
||||||
assert!(buffer.dequeue().is_ok());
|
assert!(buffer.dequeue().is_ok());
|
||||||
assert!(buffer.enqueue(5, ()).is_ok());
|
assert!(buffer.enqueue(5, ()).is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn clear() {
|
||||||
|
let mut buffer = buffer();
|
||||||
|
|
||||||
|
// Ensure enqueuing data in teh buffer fills it somewhat.
|
||||||
|
assert!(buffer.is_empty());
|
||||||
|
assert!(buffer.enqueue(6, ()).is_ok());
|
||||||
|
|
||||||
|
// Ensure that resetting the buffer causes it to be empty.
|
||||||
|
assert!(!buffer.is_empty());
|
||||||
|
buffer.reset();
|
||||||
|
assert!(buffer.is_empty());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue