2017-07-27 22:53:06 +08:00
|
|
|
use core::cmp::min;
|
2018-02-22 14:33:11 +08:00
|
|
|
use managed::ManagedSlice;
|
2017-01-10 19:04:00 +08:00
|
|
|
|
2017-07-27 21:51:02 +08:00
|
|
|
use {Error, Result};
|
2017-11-22 11:50:09 +08:00
|
|
|
use socket::{Socket, SocketMeta, SocketHandle};
|
2018-02-22 14:33:11 +08:00
|
|
|
use storage::RingBuffer;
|
2018-02-11 00:32:41 +08:00
|
|
|
use time::Instant;
|
|
|
|
use wire::{IpProtocol, IpRepr, IpEndpoint, UdpRepr};
|
2016-12-15 01:39:44 +08:00
|
|
|
|
2018-02-22 14:33:11 +08:00
|
|
|
/// Endpoint and size of an UDP packet.
|
|
|
|
#[derive(Debug, Clone, Copy, Default)]
|
|
|
|
pub struct PacketMetadata {
|
2016-12-20 21:54:11 +08:00
|
|
|
endpoint: IpEndpoint,
|
2018-02-22 14:33:11 +08:00
|
|
|
size: usize,
|
|
|
|
/// Padding packets can be used to avoid wrap-arounds of packets in the payload buffer
|
|
|
|
padding: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// An UDP packet ring buffer.
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct SocketBuffer<'a, 'b> {
|
|
|
|
metadata_buffer: RingBuffer<'a, PacketMetadata>,
|
|
|
|
payload_buffer: RingBuffer<'b, u8>,
|
2016-12-16 01:07:56 +08:00
|
|
|
}
|
2016-12-15 01:39:44 +08:00
|
|
|
|
2018-02-22 14:33:11 +08:00
|
|
|
impl<'a, 'b> SocketBuffer<'a, 'b> {
|
|
|
|
/// Create a new socket buffer with the provided metadata and payload storage.
|
|
|
|
///
|
|
|
|
/// Metadata storage limits the maximum _number_ of UDP packets in the buffer and payload
|
|
|
|
/// storage limits the maximum _cumulated size_ of UDP packets.
|
|
|
|
pub fn new<MS, PS>(metadata_storage: MS, payload_storage: PS) -> SocketBuffer<'a, 'b>
|
|
|
|
where MS: Into<ManagedSlice<'a, PacketMetadata>>, PS: Into<ManagedSlice<'b, u8>>,
|
|
|
|
{
|
|
|
|
SocketBuffer {
|
|
|
|
metadata_buffer: RingBuffer::new(metadata_storage),
|
|
|
|
payload_buffer: RingBuffer::new(payload_storage),
|
2016-12-16 01:07:56 +08:00
|
|
|
}
|
|
|
|
}
|
2016-12-17 13:12:45 +08:00
|
|
|
|
2018-02-22 14:33:11 +08:00
|
|
|
fn is_full(&self) -> bool {
|
|
|
|
self.metadata_buffer.is_full() || self.payload_buffer.is_full()
|
2016-12-17 13:12:45 +08:00
|
|
|
}
|
|
|
|
|
2018-02-22 14:33:11 +08:00
|
|
|
fn is_empty(&self) -> bool {
|
|
|
|
self.metadata_buffer.is_empty()
|
2016-12-17 13:12:45 +08:00
|
|
|
}
|
2017-07-27 22:53:06 +08:00
|
|
|
|
2018-02-22 14:33:11 +08:00
|
|
|
fn enqueue(&mut self, required_size: usize, endpoint: IpEndpoint) -> Result<&mut [u8]> {
|
|
|
|
let window = self.payload_buffer.window();
|
|
|
|
let contig_window = self.payload_buffer.contiguous_window();
|
|
|
|
|
|
|
|
if self.metadata_buffer.is_full() || self.payload_buffer.window() < required_size {
|
|
|
|
return Err(Error::Exhausted);
|
2017-07-27 22:53:06 +08:00
|
|
|
}
|
|
|
|
|
2018-02-22 14:33:11 +08:00
|
|
|
if contig_window < required_size {
|
|
|
|
// we reached the end of buffer, so the data does not fit without wrap-around
|
|
|
|
// -> insert padding and try again
|
|
|
|
self.payload_buffer.enqueue_many(required_size);
|
|
|
|
let metadata_buf = self.metadata_buffer.enqueue_one()?;
|
|
|
|
metadata_buf.padding = true;
|
|
|
|
metadata_buf.size = required_size;
|
|
|
|
metadata_buf.endpoint = IpEndpoint::default();
|
|
|
|
if window - contig_window < required_size {
|
|
|
|
return Err(Error::Exhausted);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let metadata_buf = self.metadata_buffer.enqueue_one()?;
|
|
|
|
metadata_buf.endpoint = endpoint;
|
|
|
|
metadata_buf.size = required_size;
|
|
|
|
metadata_buf.padding = false;
|
|
|
|
|
|
|
|
Ok(self.payload_buffer.enqueue_many(required_size))
|
2017-07-27 22:53:06 +08:00
|
|
|
}
|
2016-12-15 01:39:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// An User Datagram Protocol socket.
|
2016-12-15 13:15:00 +08:00
|
|
|
///
|
|
|
|
/// An UDP socket is bound to a specific endpoint, and owns transmit and receive
|
|
|
|
/// packet buffers.
|
2017-01-12 12:28:34 +08:00
|
|
|
#[derive(Debug)]
|
2016-12-17 14:27:08 +08:00
|
|
|
pub struct UdpSocket<'a, 'b: 'a> {
|
2017-11-22 11:50:09 +08:00
|
|
|
pub(crate) meta: SocketMeta,
|
2016-12-20 21:54:11 +08:00
|
|
|
endpoint: IpEndpoint,
|
2016-12-20 21:56:59 +08:00
|
|
|
rx_buffer: SocketBuffer<'a, 'b>,
|
2017-01-17 07:35:21 +08:00
|
|
|
tx_buffer: SocketBuffer<'a, 'b>,
|
2017-10-15 08:05:55 +08:00
|
|
|
/// The time-to-live (IPv4) or hop limit (IPv6) value used in outgoing packets.
|
2017-12-10 11:09:50 +08:00
|
|
|
hop_limit: Option<u8>
|
2016-12-15 01:39:44 +08:00
|
|
|
}
|
|
|
|
|
2016-12-17 14:27:08 +08:00
|
|
|
impl<'a, 'b> UdpSocket<'a, 'b> {
|
2016-12-15 01:39:44 +08:00
|
|
|
/// Create an UDP socket with the given buffers.
|
2017-01-11 13:25:54 +08:00
|
|
|
pub fn new(rx_buffer: SocketBuffer<'a, 'b>,
|
2018-01-28 22:36:23 +08:00
|
|
|
tx_buffer: SocketBuffer<'a, 'b>) -> UdpSocket<'a, 'b> {
|
|
|
|
UdpSocket {
|
2017-11-22 11:50:09 +08:00
|
|
|
meta: SocketMeta::default(),
|
2017-01-11 12:44:42 +08:00
|
|
|
endpoint: IpEndpoint::default(),
|
2016-12-15 01:39:44 +08:00
|
|
|
rx_buffer: rx_buffer,
|
2017-01-17 07:35:21 +08:00
|
|
|
tx_buffer: tx_buffer,
|
2017-12-10 11:09:50 +08:00
|
|
|
hop_limit: None
|
2018-01-28 22:36:23 +08:00
|
|
|
}
|
2016-12-15 01:39:44 +08:00
|
|
|
}
|
|
|
|
|
2017-10-05 11:02:41 +08:00
|
|
|
/// Return the socket handle.
|
2017-07-05 02:46:36 +08:00
|
|
|
#[inline]
|
2017-10-05 11:02:41 +08:00
|
|
|
pub fn handle(&self) -> SocketHandle {
|
2017-11-22 11:50:09 +08:00
|
|
|
self.meta.handle
|
2017-01-17 07:35:21 +08:00
|
|
|
}
|
|
|
|
|
2017-01-11 12:44:42 +08:00
|
|
|
/// Return the bound endpoint.
|
|
|
|
#[inline]
|
|
|
|
pub fn endpoint(&self) -> IpEndpoint {
|
|
|
|
self.endpoint
|
|
|
|
}
|
|
|
|
|
2017-10-15 08:05:55 +08:00
|
|
|
/// Return the time-to-live (IPv4) or hop limit (IPv6) value used in outgoing packets.
|
|
|
|
///
|
2017-12-10 11:09:50 +08:00
|
|
|
/// See also the [set_hop_limit](#method.set_hop_limit) method
|
|
|
|
pub fn hop_limit(&self) -> Option<u8> {
|
|
|
|
self.hop_limit
|
2017-10-15 08:05:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Set the time-to-live (IPv4) or hop limit (IPv6) value used in outgoing packets.
|
|
|
|
///
|
2017-12-10 11:09:50 +08:00
|
|
|
/// A socket without an explicitly set hop limit value uses the default [IANA recommended]
|
2017-10-25 07:04:33 +08:00
|
|
|
/// value (64).
|
2017-10-15 08:05:55 +08:00
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
///
|
2017-12-10 11:09:50 +08:00
|
|
|
/// This function panics if a hop limit value of 0 is given. See [RFC 1122 § 3.2.1.7].
|
2017-10-15 08:05:55 +08:00
|
|
|
///
|
|
|
|
/// [IANA recommended]: https://www.iana.org/assignments/ip-parameters/ip-parameters.xhtml
|
|
|
|
/// [RFC 1122 § 3.2.1.7]: https://tools.ietf.org/html/rfc1122#section-3.2.1.7
|
2017-12-10 11:09:50 +08:00
|
|
|
pub fn set_hop_limit(&mut self, hop_limit: Option<u8>) {
|
|
|
|
// A host MUST NOT send a datagram with a hop limit value of 0
|
|
|
|
if let Some(0) = hop_limit {
|
2017-10-25 07:04:33 +08:00
|
|
|
panic!("the time-to-live value of a packet must not be zero")
|
2017-10-15 08:05:55 +08:00
|
|
|
}
|
2017-10-25 07:04:33 +08:00
|
|
|
|
2017-12-10 11:09:50 +08:00
|
|
|
self.hop_limit = hop_limit
|
2017-10-15 08:05:55 +08:00
|
|
|
}
|
|
|
|
|
2017-01-11 12:44:42 +08:00
|
|
|
/// Bind the socket to the given endpoint.
|
2017-07-27 22:53:06 +08:00
|
|
|
///
|
2017-07-30 09:17:48 +08:00
|
|
|
/// This function returns `Err(Error::Illegal)` if the socket was open
|
|
|
|
/// (see [is_open](#method.is_open)), and `Err(Error::Unaddressable)`
|
|
|
|
/// if the port in the given endpoint is zero.
|
2017-07-27 22:53:06 +08:00
|
|
|
pub fn bind<T: Into<IpEndpoint>>(&mut self, endpoint: T) -> Result<()> {
|
|
|
|
let endpoint = endpoint.into();
|
|
|
|
if endpoint.port == 0 { return Err(Error::Unaddressable) }
|
|
|
|
|
2017-07-30 09:17:48 +08:00
|
|
|
if self.is_open() { return Err(Error::Illegal) }
|
2017-07-27 22:53:06 +08:00
|
|
|
|
|
|
|
self.endpoint = endpoint;
|
|
|
|
Ok(())
|
2017-01-11 12:44:42 +08:00
|
|
|
}
|
|
|
|
|
2017-07-30 09:17:48 +08:00
|
|
|
/// Check whether the socket is open.
|
|
|
|
#[inline]
|
|
|
|
pub fn is_open(&self) -> bool {
|
|
|
|
self.endpoint.port != 0
|
|
|
|
}
|
|
|
|
|
2017-01-11 14:33:51 +08:00
|
|
|
/// Check whether the transmit buffer is full.
|
2017-07-05 02:46:36 +08:00
|
|
|
#[inline]
|
2017-01-11 14:33:51 +08:00
|
|
|
pub fn can_send(&self) -> bool {
|
2017-09-09 07:23:40 +08:00
|
|
|
!self.tx_buffer.is_full()
|
2017-01-11 14:33:51 +08:00
|
|
|
}
|
|
|
|
|
2017-01-14 14:51:29 +08:00
|
|
|
/// Check whether the receive buffer is not empty.
|
2017-07-05 02:46:36 +08:00
|
|
|
#[inline]
|
2017-01-14 14:51:29 +08:00
|
|
|
pub fn can_recv(&self) -> bool {
|
2017-09-09 07:23:40 +08:00
|
|
|
!self.rx_buffer.is_empty()
|
2017-01-14 14:51:29 +08:00
|
|
|
}
|
|
|
|
|
2016-12-16 01:07:56 +08:00
|
|
|
/// Enqueue a packet to be sent to a given remote endpoint, and return a pointer
|
|
|
|
/// to its payload.
|
2016-12-15 01:39:44 +08:00
|
|
|
///
|
2018-02-22 14:33:11 +08:00
|
|
|
/// This function returns `Err(Error::Exhausted)` if the transmit buffer is full and
|
|
|
|
/// `Err(Error::Unaddressable)` if local or remote port, or remote address are unspecified.
|
2017-07-27 21:51:02 +08:00
|
|
|
pub fn send(&mut self, size: usize, endpoint: IpEndpoint) -> Result<&mut [u8]> {
|
2017-07-27 22:53:06 +08:00
|
|
|
if self.endpoint.port == 0 { return Err(Error::Unaddressable) }
|
|
|
|
if !endpoint.is_specified() { return Err(Error::Unaddressable) }
|
|
|
|
|
2018-02-22 14:33:11 +08:00
|
|
|
let payload_buf = self.tx_buffer.enqueue(size, endpoint)?;
|
|
|
|
|
|
|
|
debug_assert_eq!(payload_buf.len(), size);
|
|
|
|
|
2017-10-05 11:02:41 +08:00
|
|
|
net_trace!("{}:{}:{}: buffer to send {} octets",
|
2018-02-22 14:33:11 +08:00
|
|
|
self.meta.handle, self.endpoint, endpoint, size);
|
|
|
|
Ok(payload_buf)
|
2016-12-17 13:12:45 +08:00
|
|
|
}
|
|
|
|
|
2016-12-26 22:50:12 +08:00
|
|
|
/// Enqueue a packet to be sent to a given remote endpoint, and fill it from a slice.
|
2016-12-17 13:12:45 +08:00
|
|
|
///
|
|
|
|
/// See also [send](#method.send).
|
2017-07-29 16:19:32 +08:00
|
|
|
pub fn send_slice(&mut self, data: &[u8], endpoint: IpEndpoint) -> Result<()> {
|
2017-07-27 22:53:06 +08:00
|
|
|
self.send(data.len(), endpoint)?.copy_from_slice(data);
|
2017-07-29 16:19:32 +08:00
|
|
|
Ok(())
|
2016-12-15 01:39:44 +08:00
|
|
|
}
|
|
|
|
|
2016-12-16 01:07:56 +08:00
|
|
|
/// Dequeue a packet received from a remote endpoint, and return the endpoint as well
|
|
|
|
/// as a pointer to the payload.
|
2016-12-15 01:39:44 +08:00
|
|
|
///
|
2017-07-27 21:51:02 +08:00
|
|
|
/// This function returns `Err(Error::Exhausted)` if the receive buffer is empty.
|
|
|
|
pub fn recv(&mut self) -> Result<(&[u8], IpEndpoint)> {
|
2018-02-22 14:33:11 +08:00
|
|
|
let mut metadata_buf = *self.rx_buffer.metadata_buffer.dequeue_one()?;
|
|
|
|
if metadata_buf.padding {
|
|
|
|
// packet is padding packet -> drop it and try again
|
|
|
|
self.rx_buffer.payload_buffer.dequeue_many(metadata_buf.size);
|
|
|
|
metadata_buf = *self.rx_buffer.metadata_buffer.dequeue_one()?;
|
|
|
|
}
|
|
|
|
|
|
|
|
debug_assert!(!metadata_buf.padding);
|
|
|
|
let payload_buf = self.rx_buffer.payload_buffer.dequeue_many(metadata_buf.size);
|
|
|
|
debug_assert_eq!(metadata_buf.size, payload_buf.len()); // ensured by inserting logic
|
|
|
|
|
2017-10-05 11:02:41 +08:00
|
|
|
net_trace!("{}:{}:{}: receive {} buffered octets",
|
2017-11-22 11:50:09 +08:00
|
|
|
self.meta.handle, self.endpoint,
|
2018-02-22 14:33:11 +08:00
|
|
|
metadata_buf.endpoint, metadata_buf.size);
|
|
|
|
Ok((payload_buf, metadata_buf.endpoint))
|
2016-12-17 13:12:45 +08:00
|
|
|
}
|
|
|
|
|
2017-11-01 03:24:54 +08:00
|
|
|
/// Dequeue a packet received from a remote endpoint, copy the payload into the given slice,
|
|
|
|
/// and return the amount of octets copied as well as the endpoint.
|
2016-12-17 13:12:45 +08:00
|
|
|
///
|
2017-01-12 12:18:18 +08:00
|
|
|
/// See also [recv](#method.recv).
|
2017-07-27 21:51:02 +08:00
|
|
|
pub fn recv_slice(&mut self, data: &mut [u8]) -> Result<(usize, IpEndpoint)> {
|
2017-06-25 00:34:32 +08:00
|
|
|
let (buffer, endpoint) = self.recv()?;
|
2017-07-27 22:53:06 +08:00
|
|
|
let length = min(data.len(), buffer.len());
|
|
|
|
data[..length].copy_from_slice(&buffer[..length]);
|
|
|
|
Ok((length, endpoint))
|
2016-12-15 01:39:44 +08:00
|
|
|
}
|
2016-12-15 13:15:00 +08:00
|
|
|
|
2017-09-01 05:44:21 +08:00
|
|
|
pub(crate) fn accepts(&self, ip_repr: &IpRepr, repr: &UdpRepr) -> bool {
|
|
|
|
if self.endpoint.port != repr.dst_port { return false }
|
2017-08-01 19:08:48 +08:00
|
|
|
if !self.endpoint.addr.is_unspecified() &&
|
2017-09-01 05:44:21 +08:00
|
|
|
self.endpoint.addr != ip_repr.dst_addr() { return false }
|
|
|
|
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn process(&mut self, ip_repr: &IpRepr, repr: &UdpRepr) -> Result<()> {
|
|
|
|
debug_assert!(self.accepts(ip_repr, repr));
|
2016-12-15 13:15:00 +08:00
|
|
|
|
2018-02-22 14:33:11 +08:00
|
|
|
let size = repr.payload.len();
|
|
|
|
|
|
|
|
let endpoint = IpEndpoint { addr: ip_repr.src_addr(), port: repr.src_port };
|
|
|
|
let payload_buf = self.rx_buffer.enqueue(size, endpoint)?;
|
|
|
|
assert_eq!(payload_buf.len(), size);
|
|
|
|
payload_buf.copy_from_slice(repr.payload);
|
|
|
|
|
2017-10-05 11:02:41 +08:00
|
|
|
net_trace!("{}:{}:{}: receiving {} octets",
|
2017-11-22 11:50:09 +08:00
|
|
|
self.meta.handle, self.endpoint,
|
2018-02-22 14:33:11 +08:00
|
|
|
endpoint, size);
|
2016-12-16 01:07:56 +08:00
|
|
|
Ok(())
|
2016-12-15 01:39:44 +08:00
|
|
|
}
|
|
|
|
|
2017-08-28 12:09:17 +08:00
|
|
|
pub(crate) fn dispatch<F>(&mut self, emit: F) -> Result<()>
|
2017-08-28 11:50:40 +08:00
|
|
|
where F: FnOnce((IpRepr, UdpRepr)) -> Result<()> {
|
2017-11-22 11:50:09 +08:00
|
|
|
let handle = self.handle();
|
2017-08-30 03:35:09 +08:00
|
|
|
let endpoint = self.endpoint;
|
2017-12-10 11:09:50 +08:00
|
|
|
let hop_limit = self.hop_limit.unwrap_or(64);
|
2018-02-22 14:33:11 +08:00
|
|
|
|
|
|
|
let SocketBuffer { ref mut metadata_buffer, ref mut payload_buffer } = self.tx_buffer;
|
|
|
|
|
|
|
|
// dequeue potential padding packet
|
|
|
|
let result = metadata_buffer.dequeue_one_with(|metadata_buf| {
|
|
|
|
if metadata_buf.padding {
|
|
|
|
Ok(metadata_buf.size) // dequeue metadata
|
|
|
|
} else {
|
|
|
|
Err(Error::Exhausted) // don't dequeue metadata
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if let Ok(size) = result {
|
|
|
|
payload_buffer.dequeue_many(size); // dequeue padding payload
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata_buffer.dequeue_one_with(move |metadata_buf| {
|
|
|
|
debug_assert!(!metadata_buf.padding);
|
|
|
|
payload_buffer.dequeue_many_with(|payload_buf| {
|
|
|
|
let payload_buf = &payload_buf[..metadata_buf.size];
|
|
|
|
|
|
|
|
net_trace!("{}:{}:{}: sending {} octets",
|
|
|
|
handle, endpoint,
|
|
|
|
metadata_buf.endpoint, metadata_buf.size);
|
|
|
|
|
|
|
|
let repr = UdpRepr {
|
|
|
|
src_port: endpoint.port,
|
|
|
|
dst_port: metadata_buf.endpoint.port,
|
|
|
|
payload: payload_buf,
|
|
|
|
};
|
|
|
|
let ip_repr = IpRepr::Unspecified {
|
|
|
|
src_addr: endpoint.addr,
|
|
|
|
dst_addr: metadata_buf.endpoint.addr,
|
|
|
|
protocol: IpProtocol::Udp,
|
|
|
|
payload_len: repr.buffer_len(),
|
|
|
|
hop_limit: hop_limit,
|
|
|
|
};
|
|
|
|
match emit((ip_repr, repr)) {
|
|
|
|
Ok(ret) => (metadata_buf.size, Ok(ret)),
|
|
|
|
Err(ret) => (0, Err(ret)),
|
|
|
|
}
|
|
|
|
}).1
|
2017-08-30 03:35:09 +08:00
|
|
|
})
|
|
|
|
}
|
2017-07-27 22:53:06 +08:00
|
|
|
|
2018-02-11 00:32:41 +08:00
|
|
|
pub(crate) fn poll_at(&self) -> Option<Instant> {
|
2017-09-09 07:23:40 +08:00
|
|
|
if self.tx_buffer.is_empty() {
|
2017-08-30 03:35:09 +08:00
|
|
|
None
|
|
|
|
} else {
|
2018-02-11 00:32:41 +08:00
|
|
|
Some(Instant::from_millis(0))
|
2017-08-30 03:35:09 +08:00
|
|
|
}
|
2016-12-15 13:15:00 +08:00
|
|
|
}
|
|
|
|
}
|
2017-07-27 22:53:06 +08:00
|
|
|
|
2018-01-28 22:36:23 +08:00
|
|
|
impl<'a, 'b> Into<Socket<'a, 'b>> for UdpSocket<'a, 'b> {
|
|
|
|
fn into(self) -> Socket<'a, 'b> {
|
|
|
|
Socket::Udp(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-27 22:53:06 +08:00
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
2017-12-24 21:28:59 +08:00
|
|
|
use wire::{IpAddress, IpRepr, UdpRepr};
|
|
|
|
#[cfg(feature = "proto-ipv4")]
|
|
|
|
use wire::Ipv4Repr;
|
|
|
|
#[cfg(feature = "proto-ipv6")]
|
|
|
|
use wire::Ipv6Repr;
|
|
|
|
use wire::ip::test::{MOCK_IP_ADDR_1, MOCK_IP_ADDR_2, MOCK_IP_ADDR_3};
|
2017-07-27 22:53:06 +08:00
|
|
|
use super::*;
|
|
|
|
|
|
|
|
fn buffer(packets: usize) -> SocketBuffer<'static, 'static> {
|
2018-02-22 14:33:11 +08:00
|
|
|
SocketBuffer::new(vec![Default::default(); packets], vec![0; 16 * packets])
|
2017-07-27 22:53:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn socket(rx_buffer: SocketBuffer<'static, 'static>,
|
|
|
|
tx_buffer: SocketBuffer<'static, 'static>)
|
|
|
|
-> UdpSocket<'static, 'static> {
|
2018-01-28 22:36:23 +08:00
|
|
|
UdpSocket::new(rx_buffer, tx_buffer)
|
2017-07-27 22:53:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const LOCAL_PORT: u16 = 53;
|
|
|
|
const REMOTE_PORT: u16 = 49500;
|
2017-12-24 21:28:59 +08:00
|
|
|
|
|
|
|
pub const LOCAL_END: IpEndpoint = IpEndpoint { addr: MOCK_IP_ADDR_1, port: LOCAL_PORT };
|
|
|
|
pub const REMOTE_END: IpEndpoint = IpEndpoint { addr: MOCK_IP_ADDR_2, port: REMOTE_PORT };
|
|
|
|
|
|
|
|
pub const LOCAL_IP_REPR: IpRepr = IpRepr::Unspecified {
|
|
|
|
src_addr: MOCK_IP_ADDR_1,
|
|
|
|
dst_addr: MOCK_IP_ADDR_2,
|
|
|
|
protocol: IpProtocol::Udp,
|
|
|
|
payload_len: 8 + 6,
|
|
|
|
hop_limit: 64,
|
|
|
|
};
|
|
|
|
|
|
|
|
const LOCAL_UDP_REPR: UdpRepr = UdpRepr {
|
|
|
|
src_port: LOCAL_PORT,
|
|
|
|
dst_port: REMOTE_PORT,
|
|
|
|
payload: b"abcdef"
|
|
|
|
};
|
|
|
|
|
|
|
|
const REMOTE_UDP_REPR: UdpRepr = UdpRepr {
|
|
|
|
src_port: REMOTE_PORT,
|
|
|
|
dst_port: LOCAL_PORT,
|
|
|
|
payload: b"abcdef"
|
|
|
|
};
|
|
|
|
|
|
|
|
fn remote_ip_repr() -> IpRepr {
|
|
|
|
match (MOCK_IP_ADDR_2, MOCK_IP_ADDR_1) {
|
|
|
|
#[cfg(feature = "proto-ipv4")]
|
|
|
|
(IpAddress::Ipv4(src), IpAddress::Ipv4(dst)) => IpRepr::Ipv4(Ipv4Repr {
|
|
|
|
src_addr: src,
|
|
|
|
dst_addr: dst,
|
|
|
|
protocol: IpProtocol::Udp,
|
|
|
|
payload_len: 8 + 6,
|
|
|
|
hop_limit: 64
|
|
|
|
}),
|
|
|
|
#[cfg(feature = "proto-ipv6")]
|
|
|
|
(IpAddress::Ipv6(src), IpAddress::Ipv6(dst)) => IpRepr::Ipv6(Ipv6Repr {
|
|
|
|
src_addr: src,
|
|
|
|
dst_addr: dst,
|
|
|
|
next_header: IpProtocol::Udp,
|
|
|
|
payload_len: 8 + 6,
|
|
|
|
hop_limit: 64
|
|
|
|
}),
|
|
|
|
_ => unreachable!()
|
|
|
|
}
|
|
|
|
}
|
2017-07-27 22:53:06 +08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_bind_unaddressable() {
|
|
|
|
let mut socket = socket(buffer(0), buffer(0));
|
|
|
|
assert_eq!(socket.bind(0), Err(Error::Unaddressable));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_bind_twice() {
|
|
|
|
let mut socket = socket(buffer(0), buffer(0));
|
|
|
|
assert_eq!(socket.bind(1), Ok(()));
|
|
|
|
assert_eq!(socket.bind(2), Err(Error::Illegal));
|
|
|
|
}
|
|
|
|
|
2017-12-24 21:28:59 +08:00
|
|
|
#[test]
|
|
|
|
#[should_panic(expected = "the time-to-live value of a packet must not be zero")]
|
|
|
|
fn test_set_hop_limit_zero() {
|
|
|
|
let mut s = socket(buffer(0), buffer(1));
|
|
|
|
s.set_hop_limit(Some(0));
|
|
|
|
}
|
2017-07-27 22:53:06 +08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_send_unaddressable() {
|
|
|
|
let mut socket = socket(buffer(0), buffer(1));
|
|
|
|
assert_eq!(socket.send_slice(b"abcdef", REMOTE_END), Err(Error::Unaddressable));
|
2017-07-31 15:59:01 +08:00
|
|
|
assert_eq!(socket.bind(LOCAL_PORT), Ok(()));
|
2017-07-27 22:53:06 +08:00
|
|
|
assert_eq!(socket.send_slice(b"abcdef",
|
|
|
|
IpEndpoint { addr: IpAddress::Unspecified, ..REMOTE_END }),
|
|
|
|
Err(Error::Unaddressable));
|
|
|
|
assert_eq!(socket.send_slice(b"abcdef",
|
|
|
|
IpEndpoint { port: 0, ..REMOTE_END }),
|
|
|
|
Err(Error::Unaddressable));
|
2017-07-29 16:19:32 +08:00
|
|
|
assert_eq!(socket.send_slice(b"abcdef", REMOTE_END), Ok(()));
|
2017-07-27 22:53:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_send_dispatch() {
|
|
|
|
let mut socket = socket(buffer(0), buffer(1));
|
2017-07-31 15:59:01 +08:00
|
|
|
assert_eq!(socket.bind(LOCAL_END), Ok(()));
|
2017-07-27 22:53:06 +08:00
|
|
|
|
|
|
|
assert!(socket.can_send());
|
2017-08-28 12:09:17 +08:00
|
|
|
assert_eq!(socket.dispatch(|_| unreachable!()),
|
2017-08-28 11:50:40 +08:00
|
|
|
Err(Error::Exhausted));
|
2017-07-27 22:53:06 +08:00
|
|
|
|
2017-07-29 16:19:32 +08:00
|
|
|
assert_eq!(socket.send_slice(b"abcdef", REMOTE_END), Ok(()));
|
2017-07-27 22:53:06 +08:00
|
|
|
assert_eq!(socket.send_slice(b"123456", REMOTE_END), Err(Error::Exhausted));
|
|
|
|
assert!(!socket.can_send());
|
|
|
|
|
2017-08-28 12:09:17 +08:00
|
|
|
assert_eq!(socket.dispatch(|(ip_repr, udp_repr)| {
|
2017-08-28 11:50:40 +08:00
|
|
|
assert_eq!(ip_repr, LOCAL_IP_REPR);
|
|
|
|
assert_eq!(udp_repr, LOCAL_UDP_REPR);
|
2017-07-27 22:53:06 +08:00
|
|
|
Err(Error::Unaddressable)
|
2017-08-28 11:50:40 +08:00
|
|
|
}), Err(Error::Unaddressable));
|
2017-08-30 03:35:09 +08:00
|
|
|
assert!(!socket.can_send());
|
2017-07-27 22:53:06 +08:00
|
|
|
|
2017-08-28 12:09:17 +08:00
|
|
|
assert_eq!(socket.dispatch(|(ip_repr, udp_repr)| {
|
2017-08-28 11:50:40 +08:00
|
|
|
assert_eq!(ip_repr, LOCAL_IP_REPR);
|
|
|
|
assert_eq!(udp_repr, LOCAL_UDP_REPR);
|
2017-07-27 22:53:06 +08:00
|
|
|
Ok(())
|
2017-08-30 03:35:09 +08:00
|
|
|
}), Ok(()));
|
2017-07-27 22:53:06 +08:00
|
|
|
assert!(socket.can_send());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_recv_process() {
|
|
|
|
let mut socket = socket(buffer(1), buffer(0));
|
2017-07-31 15:59:01 +08:00
|
|
|
assert_eq!(socket.bind(LOCAL_PORT), Ok(()));
|
2017-07-27 22:53:06 +08:00
|
|
|
|
2017-07-31 15:59:01 +08:00
|
|
|
assert!(!socket.can_recv());
|
2017-07-27 22:53:06 +08:00
|
|
|
assert_eq!(socket.recv(), Err(Error::Exhausted));
|
2017-07-31 15:59:01 +08:00
|
|
|
|
2017-12-24 21:28:59 +08:00
|
|
|
assert!(socket.accepts(&remote_ip_repr(), &REMOTE_UDP_REPR));
|
|
|
|
assert_eq!(socket.process(&remote_ip_repr(), &REMOTE_UDP_REPR),
|
2017-07-27 22:53:06 +08:00
|
|
|
Ok(()));
|
|
|
|
assert!(socket.can_recv());
|
|
|
|
|
2017-12-24 21:28:59 +08:00
|
|
|
assert!(socket.accepts(&remote_ip_repr(), &REMOTE_UDP_REPR));
|
|
|
|
assert_eq!(socket.process(&remote_ip_repr(), &REMOTE_UDP_REPR),
|
2017-07-27 22:53:06 +08:00
|
|
|
Err(Error::Exhausted));
|
|
|
|
assert_eq!(socket.recv(), Ok((&b"abcdef"[..], REMOTE_END)));
|
|
|
|
assert!(!socket.can_recv());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_recv_truncated_slice() {
|
|
|
|
let mut socket = socket(buffer(1), buffer(0));
|
2017-07-31 15:59:01 +08:00
|
|
|
assert_eq!(socket.bind(LOCAL_PORT), Ok(()));
|
2017-07-27 22:53:06 +08:00
|
|
|
|
2017-12-24 21:28:59 +08:00
|
|
|
assert!(socket.accepts(&remote_ip_repr(), &REMOTE_UDP_REPR));
|
|
|
|
assert_eq!(socket.process(&remote_ip_repr(), &REMOTE_UDP_REPR),
|
2017-08-28 12:50:57 +08:00
|
|
|
Ok(()));
|
2017-07-27 22:53:06 +08:00
|
|
|
|
|
|
|
let mut slice = [0; 4];
|
|
|
|
assert_eq!(socket.recv_slice(&mut slice[..]), Ok((4, REMOTE_END)));
|
|
|
|
assert_eq!(&slice, b"abcd");
|
|
|
|
}
|
|
|
|
|
2017-10-25 07:04:33 +08:00
|
|
|
#[test]
|
2017-12-10 11:09:50 +08:00
|
|
|
fn test_set_hop_limit() {
|
2017-10-25 07:04:33 +08:00
|
|
|
let mut s = socket(buffer(0), buffer(1));
|
|
|
|
assert_eq!(s.bind(LOCAL_END), Ok(()));
|
|
|
|
|
2017-12-10 11:09:50 +08:00
|
|
|
s.set_hop_limit(Some(0x2a));
|
2017-10-25 07:04:33 +08:00
|
|
|
assert_eq!(s.send_slice(b"abcdef", REMOTE_END), Ok(()));
|
|
|
|
assert_eq!(s.dispatch(|(ip_repr, _)| {
|
|
|
|
assert_eq!(ip_repr, IpRepr::Unspecified{
|
2017-12-24 21:28:59 +08:00
|
|
|
src_addr: MOCK_IP_ADDR_1,
|
|
|
|
dst_addr: MOCK_IP_ADDR_2,
|
2017-10-25 07:04:33 +08:00
|
|
|
protocol: IpProtocol::Udp,
|
|
|
|
payload_len: 8 + 6,
|
2017-12-10 11:09:50 +08:00
|
|
|
hop_limit: 0x2a,
|
2017-10-25 07:04:33 +08:00
|
|
|
});
|
|
|
|
Ok(())
|
|
|
|
}), Ok(()));
|
|
|
|
}
|
|
|
|
|
2017-09-01 05:44:21 +08:00
|
|
|
#[test]
|
|
|
|
fn test_doesnt_accept_wrong_port() {
|
|
|
|
let mut socket = socket(buffer(1), buffer(0));
|
|
|
|
assert_eq!(socket.bind(LOCAL_PORT), Ok(()));
|
|
|
|
|
|
|
|
let mut udp_repr = REMOTE_UDP_REPR;
|
2017-12-24 21:28:59 +08:00
|
|
|
assert!(socket.accepts(&remote_ip_repr(), &udp_repr));
|
2017-09-01 05:44:21 +08:00
|
|
|
udp_repr.dst_port += 1;
|
2017-12-24 21:28:59 +08:00
|
|
|
assert!(!socket.accepts(&remote_ip_repr(), &udp_repr));
|
2017-09-01 05:44:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_doesnt_accept_wrong_ip() {
|
2017-12-24 21:28:59 +08:00
|
|
|
fn generate_bad_repr() -> IpRepr {
|
|
|
|
match (MOCK_IP_ADDR_2, MOCK_IP_ADDR_3) {
|
|
|
|
#[cfg(feature = "proto-ipv4")]
|
|
|
|
(IpAddress::Ipv4(src), IpAddress::Ipv4(dst)) => IpRepr::Ipv4(Ipv4Repr {
|
|
|
|
src_addr: src,
|
|
|
|
dst_addr: dst,
|
|
|
|
protocol: IpProtocol::Udp,
|
|
|
|
payload_len: 8 + 6,
|
|
|
|
hop_limit: 64
|
|
|
|
}),
|
|
|
|
#[cfg(feature = "proto-ipv6")]
|
|
|
|
(IpAddress::Ipv6(src), IpAddress::Ipv6(dst)) => IpRepr::Ipv6(Ipv6Repr {
|
|
|
|
src_addr: src,
|
|
|
|
dst_addr: dst,
|
|
|
|
next_header: IpProtocol::Udp,
|
|
|
|
payload_len: 8 + 6,
|
|
|
|
hop_limit: 64
|
|
|
|
}),
|
|
|
|
_ => unreachable!()
|
|
|
|
}
|
|
|
|
}
|
2017-09-01 05:44:21 +08:00
|
|
|
|
|
|
|
let mut port_bound_socket = socket(buffer(1), buffer(0));
|
|
|
|
assert_eq!(port_bound_socket.bind(LOCAL_PORT), Ok(()));
|
2017-12-24 21:28:59 +08:00
|
|
|
assert!(port_bound_socket.accepts(&generate_bad_repr(), &REMOTE_UDP_REPR));
|
2017-09-01 05:44:21 +08:00
|
|
|
|
|
|
|
let mut ip_bound_socket = socket(buffer(1), buffer(0));
|
|
|
|
assert_eq!(ip_bound_socket.bind(LOCAL_END), Ok(()));
|
2017-12-24 21:28:59 +08:00
|
|
|
assert!(!ip_bound_socket.accepts(&generate_bad_repr(), &REMOTE_UDP_REPR));
|
2017-09-01 05:44:21 +08:00
|
|
|
}
|
2018-02-22 14:33:11 +08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_send_large_packet() {
|
|
|
|
// buffer(4) creates a payload buffer of size 16*4
|
|
|
|
let mut socket = socket(buffer(0), buffer(4));
|
|
|
|
assert_eq!(socket.bind(LOCAL_END), Ok(()));
|
|
|
|
|
|
|
|
let too_large = b"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdefx";
|
|
|
|
assert_eq!(socket.send_slice(too_large, REMOTE_END), Err(Error::Exhausted));
|
|
|
|
assert_eq!(socket.send_slice(&too_large[..16*4], REMOTE_END), Ok(()));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_send_wraparound_1() {
|
|
|
|
let mut socket = socket(buffer(0), buffer(3));
|
|
|
|
assert_eq!(socket.bind(LOCAL_END), Ok(()));
|
|
|
|
|
|
|
|
let large = b"0123456789abcdef0123456789abcdef0123456789abcdef";
|
|
|
|
|
|
|
|
assert_eq!(socket.send_slice(&large[..15], REMOTE_END), Ok(()));
|
|
|
|
assert_eq!(socket.send_slice(&large[..16*2], REMOTE_END), Ok(()));
|
|
|
|
// no padding should be inserted because capacity does not suffice
|
|
|
|
assert_eq!(socket.send_slice(b"12", REMOTE_END), Err(Error::Exhausted));
|
|
|
|
assert_eq!(socket.tx_buffer.metadata_buffer.len(), 2);
|
|
|
|
assert_eq!(socket.tx_buffer.payload_buffer.len(), 16*3-1);
|
|
|
|
|
|
|
|
assert_eq!(socket.dispatch(|_| Ok(())), Ok(()));
|
|
|
|
// insert padding
|
|
|
|
assert_eq!(socket.send_slice(&large[..16], REMOTE_END), Err(Error::Exhausted));
|
|
|
|
assert_eq!(socket.tx_buffer.metadata_buffer.len(), 2);
|
|
|
|
assert_eq!(socket.tx_buffer.payload_buffer.len(), 16*3-15);
|
|
|
|
|
|
|
|
assert_eq!(socket.dispatch(|_| Ok(())), Ok(()));
|
|
|
|
// packet dequed, but padding is still there
|
|
|
|
assert_eq!(socket.tx_buffer.metadata_buffer.len(), 1);
|
|
|
|
assert_eq!(socket.tx_buffer.payload_buffer.len(), 1);
|
|
|
|
|
|
|
|
assert_eq!(socket.dispatch(|_| Ok(())), Err(Error::Exhausted));
|
|
|
|
assert_eq!(socket.tx_buffer.metadata_buffer.len(), 0);
|
|
|
|
assert_eq!(socket.tx_buffer.payload_buffer.len(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_send_wraparound_2() {
|
|
|
|
let mut socket = socket(buffer(0), buffer(3));
|
|
|
|
assert_eq!(socket.bind(LOCAL_END), Ok(()));
|
|
|
|
|
|
|
|
let large = b"0123456789abcdef0123456789abcdef0123456789abcdef";
|
|
|
|
|
|
|
|
assert_eq!(socket.send_slice(&large[..16*2], REMOTE_END), Ok(()));
|
|
|
|
assert_eq!(socket.send_slice(&large[..15], REMOTE_END), Ok(()));
|
|
|
|
// no padding should be inserted because capacity does not suffice
|
|
|
|
assert_eq!(socket.send_slice(b"12", REMOTE_END), Err(Error::Exhausted));
|
|
|
|
assert_eq!(socket.tx_buffer.metadata_buffer.len(), 2);
|
|
|
|
assert_eq!(socket.tx_buffer.payload_buffer.len(), 16*3-1);
|
|
|
|
|
|
|
|
assert_eq!(socket.dispatch(|_| Ok(())), Ok(()));
|
|
|
|
// insert padding and slice
|
|
|
|
assert_eq!(socket.send_slice(&large[..16*2], REMOTE_END), Ok(()));
|
|
|
|
assert_eq!(socket.tx_buffer.metadata_buffer.len(), 3);
|
|
|
|
assert_eq!(socket.tx_buffer.payload_buffer.len(), 16*3);
|
|
|
|
|
|
|
|
assert_eq!(socket.dispatch(|_| Ok(())), Ok(()));
|
|
|
|
// packet dequed, but padding is still there
|
|
|
|
assert_eq!(socket.tx_buffer.metadata_buffer.len(), 2);
|
|
|
|
assert_eq!(socket.tx_buffer.payload_buffer.len(), 16*3-15);
|
|
|
|
|
|
|
|
assert_eq!(socket.dispatch(|_| Ok(())), Ok(()));
|
|
|
|
// padding and packet dequeued
|
|
|
|
assert_eq!(socket.tx_buffer.metadata_buffer.len(), 0);
|
|
|
|
assert_eq!(socket.tx_buffer.payload_buffer.len(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_process_wraparound() {
|
|
|
|
// every packet will be 6 bytes
|
|
|
|
let recv_buffer = SocketBuffer::new(vec![Default::default(); 4], vec![0; 6*3 + 2]);
|
|
|
|
let mut socket = socket(recv_buffer, buffer(0));
|
|
|
|
assert_eq!(socket.bind(LOCAL_PORT), Ok(()));
|
|
|
|
|
|
|
|
assert_eq!(socket.process(&remote_ip_repr(), &REMOTE_UDP_REPR), Ok(()));
|
|
|
|
assert_eq!(socket.process(&remote_ip_repr(), &REMOTE_UDP_REPR), Ok(()));
|
|
|
|
assert_eq!(socket.process(&remote_ip_repr(), &REMOTE_UDP_REPR), Ok(()));
|
|
|
|
assert_eq!(socket.rx_buffer.metadata_buffer.len(), 3);
|
|
|
|
assert_eq!(socket.rx_buffer.payload_buffer.len(), 6*3);
|
|
|
|
|
|
|
|
assert_eq!(socket.process(&remote_ip_repr(), &REMOTE_UDP_REPR),
|
|
|
|
Err(Error::Exhausted));
|
|
|
|
// no padding inserted because capacity does not suffice
|
|
|
|
assert_eq!(socket.rx_buffer.metadata_buffer.len(), 3);
|
|
|
|
assert_eq!(socket.rx_buffer.payload_buffer.len(), 6*3);
|
|
|
|
|
|
|
|
assert_eq!(socket.recv(), Ok((&b"abcdef"[..], REMOTE_END)));
|
|
|
|
assert_eq!(socket.process(&remote_ip_repr(), &REMOTE_UDP_REPR), Ok(()));
|
|
|
|
// padding inserted
|
|
|
|
assert_eq!(socket.rx_buffer.metadata_buffer.len(), 4);
|
|
|
|
assert_eq!(socket.rx_buffer.payload_buffer.len(), 6*3 + 2);
|
|
|
|
|
|
|
|
assert_eq!(socket.recv(), Ok((&b"abcdef"[..], REMOTE_END)));
|
|
|
|
assert_eq!(socket.recv(), Ok((&b"abcdef"[..], REMOTE_END)));
|
|
|
|
// two packets dequed, last packet and padding still there
|
|
|
|
assert_eq!(socket.rx_buffer.metadata_buffer.len(), 2);
|
|
|
|
assert_eq!(socket.rx_buffer.payload_buffer.len(), 6 + 2);
|
|
|
|
|
|
|
|
assert_eq!(socket.recv(), Ok((&b"abcdef"[..], REMOTE_END)));
|
|
|
|
// everything dequed
|
|
|
|
assert_eq!(socket.rx_buffer.metadata_buffer.len(), 0);
|
|
|
|
assert_eq!(socket.rx_buffer.payload_buffer.len(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_process_empty_payload() {
|
|
|
|
// every packet will be 6 bytes
|
|
|
|
let recv_buffer = SocketBuffer::new(vec![Default::default(); 1], vec![]);
|
|
|
|
let mut socket = socket(recv_buffer, buffer(0));
|
|
|
|
assert_eq!(socket.bind(LOCAL_PORT), Ok(()));
|
|
|
|
|
|
|
|
let repr = UdpRepr {
|
|
|
|
src_port: REMOTE_PORT,
|
|
|
|
dst_port: LOCAL_PORT,
|
|
|
|
payload: &[]
|
|
|
|
};
|
|
|
|
|
|
|
|
assert_eq!(socket.process(&remote_ip_repr(), &repr), Ok(()));
|
|
|
|
assert_eq!(socket.rx_buffer.metadata_buffer.len(), 1);
|
|
|
|
assert_eq!(socket.rx_buffer.payload_buffer.len(), 0);
|
|
|
|
|
|
|
|
// The metatdata has been queued into the metadata buffer
|
|
|
|
assert!(!socket.rx_buffer.metadata_buffer.is_empty());
|
|
|
|
// The no payload data has been queued into the payload buffer
|
|
|
|
assert!(socket.rx_buffer.payload_buffer.is_empty());
|
|
|
|
// The received packets buffer is not empty and we can recv
|
|
|
|
assert!(socket.can_recv());
|
|
|
|
assert_eq!(socket.recv(), Ok((&[][..], REMOTE_END)));
|
|
|
|
assert_eq!(socket.process(&remote_ip_repr(), &repr), Ok(()));
|
|
|
|
assert_eq!(socket.recv(), Ok((&[][..], REMOTE_END)));
|
|
|
|
}
|
2017-07-27 22:53:06 +08:00
|
|
|
}
|