Skip to content

Commit

Permalink
fn PacketMetadata::empty() → const PacketMetadata::EMPTY.
Browse files Browse the repository at this point in the history
Fixes #181.
  • Loading branch information
whitequark committed Mar 24, 2018
1 parent 9b68b08 commit cd893e6
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 21 deletions.
4 changes: 2 additions & 2 deletions examples/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ fn main() {
let remote_addr = address;
let local_addr = Ipv4Address::new(192, 168, 69, 1);

let icmp_rx_buffer = IcmpSocketBuffer::new(vec![IcmpPacketMetadata::empty()], vec![0; 256]);
let icmp_tx_buffer = IcmpSocketBuffer::new(vec![IcmpPacketMetadata::empty()], vec![0; 256]);
let icmp_rx_buffer = IcmpSocketBuffer::new(vec![IcmpPacketMetadata::EMPTY], vec![0; 256]);
let icmp_tx_buffer = IcmpSocketBuffer::new(vec![IcmpPacketMetadata::EMPTY], vec![0; 256]);
let icmp_socket = IcmpSocket::new(icmp_rx_buffer, icmp_tx_buffer);

let ethernet_addr = EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x02]);
Expand Down
4 changes: 2 additions & 2 deletions examples/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ fn main() {

let neighbor_cache = NeighborCache::new(BTreeMap::new());

let udp_rx_buffer = UdpSocketBuffer::new(vec![UdpPacketMetadata::empty()], vec![0; 64]);
let udp_tx_buffer = UdpSocketBuffer::new(vec![UdpPacketMetadata::empty()], vec![0; 128]);
let udp_rx_buffer = UdpSocketBuffer::new(vec![UdpPacketMetadata::EMPTY], vec![0; 64]);
let udp_tx_buffer = UdpSocketBuffer::new(vec![UdpPacketMetadata::EMPTY], vec![0; 128]);
let udp_socket = UdpSocket::new(udp_rx_buffer, udp_tx_buffer);

let tcp1_rx_buffer = TcpSocketBuffer::new(vec![0; 64]);
Expand Down
8 changes: 4 additions & 4 deletions src/iface/ethernet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1427,8 +1427,8 @@ mod test {

let (iface, mut socket_set) = create_loopback();

let rx_buffer = UdpSocketBuffer::new(vec![UdpPacketMetadata::empty()], vec![0; 15]);
let tx_buffer = UdpSocketBuffer::new(vec![UdpPacketMetadata::empty()], vec![0; 15]);
let rx_buffer = UdpSocketBuffer::new(vec![UdpPacketMetadata::EMPTY], vec![0; 15]);
let tx_buffer = UdpSocketBuffer::new(vec![UdpPacketMetadata::EMPTY], vec![0; 15]);

let udp_socket = UdpSocket::new(rx_buffer, tx_buffer);

Expand Down Expand Up @@ -1624,8 +1624,8 @@ mod test {

let (iface, mut socket_set) = create_loopback();

let rx_buffer = IcmpSocketBuffer::new(vec![IcmpPacketMetadata::empty()], vec![0; 24]);
let tx_buffer = IcmpSocketBuffer::new(vec![IcmpPacketMetadata::empty()], vec![0; 24]);
let rx_buffer = IcmpSocketBuffer::new(vec![IcmpPacketMetadata::EMPTY], vec![0; 24]);
let tx_buffer = IcmpSocketBuffer::new(vec![IcmpPacketMetadata::EMPTY], vec![0; 24]);

let icmpv4_socket = IcmpSocket::new(rx_buffer, tx_buffer);

Expand Down
10 changes: 5 additions & 5 deletions src/socket/icmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ impl<'a, 'b> IcmpSocket<'a, 'b> {
///
/// ```
/// # use smoltcp::socket::{Socket, IcmpSocket, IcmpSocketBuffer, IcmpPacketMetadata};
/// # let rx_buffer = IcmpSocketBuffer::new(vec![IcmpPacketMetadata::empty()], vec![0; 20]);
/// # let tx_buffer = IcmpSocketBuffer::new(vec![IcmpPacketMetadata::empty()], vec![0; 20]);
/// # let rx_buffer = IcmpSocketBuffer::new(vec![IcmpPacketMetadata::EMPTY], vec![0; 20]);
/// # let tx_buffer = IcmpSocketBuffer::new(vec![IcmpPacketMetadata::EMPTY], vec![0; 20]);
/// use smoltcp::wire::IpEndpoint;
/// use smoltcp::socket::IcmpEndpoint;
///
Expand All @@ -146,8 +146,8 @@ impl<'a, 'b> IcmpSocket<'a, 'b> {
///
/// ```
/// # use smoltcp::socket::{Socket, IcmpSocket, IcmpSocketBuffer, IcmpPacketMetadata};
/// # let rx_buffer = IcmpSocketBuffer::new(vec![IcmpPacketMetadata::empty()], vec![0; 20]);
/// # let tx_buffer = IcmpSocketBuffer::new(vec![IcmpPacketMetadata::empty()], vec![0; 20]);
/// # let rx_buffer = IcmpSocketBuffer::new(vec![IcmpPacketMetadata::EMPTY], vec![0; 20]);
/// # let tx_buffer = IcmpSocketBuffer::new(vec![IcmpPacketMetadata::EMPTY], vec![0; 20]);
/// use smoltcp::socket::IcmpEndpoint;
///
/// let mut icmp_socket = // ...
Expand Down Expand Up @@ -326,7 +326,7 @@ mod test {
use super::*;

fn buffer(packets: usize) -> IcmpSocketBuffer<'static, 'static> {
IcmpSocketBuffer::new(vec![IcmpPacketMetadata::empty(); packets], vec![0; 46 * packets])
IcmpSocketBuffer::new(vec![IcmpPacketMetadata::EMPTY; packets], vec![0; 46 * packets])
}

fn socket(rx_buffer: IcmpSocketBuffer<'static, 'static>,
Expand Down
2 changes: 1 addition & 1 deletion src/socket/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ mod test {
use super::*;

fn buffer(packets: usize) -> RawSocketBuffer<'static, 'static> {
RawSocketBuffer::new(vec![RawPacketMetadata::empty(); packets], vec![0; 48 * packets])
RawSocketBuffer::new(vec![RawPacketMetadata::EMPTY; packets], vec![0; 48 * packets])
}

#[cfg(feature = "proto-ipv4")]
Expand Down
4 changes: 2 additions & 2 deletions src/socket/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ mod test {
use super::*;

fn buffer(packets: usize) -> UdpSocketBuffer<'static, 'static> {
UdpSocketBuffer::new(vec![UdpPacketMetadata::empty(); packets], vec![0; 16 * packets])
UdpSocketBuffer::new(vec![UdpPacketMetadata::EMPTY; packets], vec![0; 16 * packets])
}

fn socket(rx_buffer: UdpSocketBuffer<'static, 'static>,
Expand Down Expand Up @@ -467,7 +467,7 @@ mod test {

#[test]
fn test_process_empty_payload() {
let recv_buffer = UdpSocketBuffer::new(vec![UdpPacketMetadata::empty(); 1], vec![]);
let recv_buffer = UdpSocketBuffer::new(vec![UdpPacketMetadata::EMPTY; 1], vec![]);
let mut socket = socket(recv_buffer, buffer(0));
assert_eq!(socket.bind(LOCAL_PORT), Ok(()));

Expand Down
8 changes: 3 additions & 5 deletions src/storage/packet_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ pub struct PacketMetadata<H> {
}

impl<H> PacketMetadata<H> {
/// Create an empty packet description.
pub fn empty() -> PacketMetadata<H> {
Self::padding(0)
}
/// Empty packet description.
pub const EMPTY: PacketMetadata<H> = PacketMetadata { size: 0, header: None };

fn padding(size: usize) -> PacketMetadata<H> {
PacketMetadata {
Expand Down Expand Up @@ -155,7 +153,7 @@ mod test {
use super::*;

fn buffer() -> PacketBuffer<'static, 'static, ()> {
PacketBuffer::new(vec![PacketMetadata::empty(); 4],
PacketBuffer::new(vec![PacketMetadata::EMPTY; 4],
vec![0u8; 16])
}

Expand Down

0 comments on commit cd893e6

Please sign in to comment.