Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/dhcp/clientv4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ impl Client {
/// Instant::now()
/// );
/// ```
pub fn new<'a, 'b, 'c>(sockets: &mut SocketSet<'a, 'b, 'c>, rx_buffer: RawSocketBuffer<'b, 'c>, tx_buffer: RawSocketBuffer<'b, 'c>, now: Instant) -> Self
where 'b: 'c,
pub fn new<'a, 'b>(sockets: &mut SocketSet<'a, 'b>, rx_buffer: RawSocketBuffer<'b>, tx_buffer: RawSocketBuffer<'b>, now: Instant) -> Self
{
let raw_socket = RawSocket::new(IpVersion::Ipv4, IpProtocol::Udp, rx_buffer, tx_buffer);
let raw_handle = sockets.add(raw_socket);
Expand Down
2 changes: 1 addition & 1 deletion src/iface/ethernet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,7 @@ mod test {
use super::{EthernetPacket, IpPacket};

fn create_loopback<'a, 'b, 'c>() -> (EthernetInterface<'static, 'b, 'c, Loopback>,
SocketSet<'static, 'a, 'b>) {
SocketSet<'static, 'a>) {
// Create a basic device
let device = Loopback::new();
let ip_addrs = [
Expand Down
24 changes: 12 additions & 12 deletions src/socket/icmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Default for Endpoint {
pub type IcmpPacketMetadata = PacketMetadata<IpAddress>;

/// An ICMP packet ring buffer.
pub type IcmpSocketBuffer<'a, 'b> = PacketBuffer<'a, 'b, IpAddress>;
pub type IcmpSocketBuffer<'a> = PacketBuffer<'a, IpAddress>;

/// A ICMP socket
///
Expand All @@ -58,10 +58,10 @@ pub type IcmpSocketBuffer<'a, 'b> = PacketBuffer<'a, 'b, IpAddress>;
/// [IcmpEndpoint]: enum.IcmpEndpoint.html
/// [bind]: #method.bind
#[derive(Debug)]
pub struct IcmpSocket<'a, 'b: 'a> {
pub struct IcmpSocket<'a> {
pub(crate) meta: SocketMeta,
rx_buffer: IcmpSocketBuffer<'a, 'b>,
tx_buffer: IcmpSocketBuffer<'a, 'b>,
rx_buffer: IcmpSocketBuffer<'a>,
tx_buffer: IcmpSocketBuffer<'a>,
/// The endpoint this socket is communicating with
endpoint: Endpoint,
/// The time-to-live (IPv4) or hop limit (IPv6) value used in outgoing packets.
Expand All @@ -72,10 +72,10 @@ pub struct IcmpSocket<'a, 'b: 'a> {
tx_waker: WakerRegistration,
}

impl<'a, 'b> IcmpSocket<'a, 'b> {
impl<'a> IcmpSocket<'a> {
/// Create an ICMP socket with the given buffers.
pub fn new(rx_buffer: IcmpSocketBuffer<'a, 'b>,
tx_buffer: IcmpSocketBuffer<'a, 'b>) -> IcmpSocket<'a, 'b> {
pub fn new(rx_buffer: IcmpSocketBuffer<'a>,
tx_buffer: IcmpSocketBuffer<'a>) -> IcmpSocket<'a> {
IcmpSocket {
meta: SocketMeta::default(),
rx_buffer: rx_buffer,
Expand Down Expand Up @@ -455,8 +455,8 @@ impl<'a, 'b> IcmpSocket<'a, 'b> {
}
}

impl<'a, 'b> Into<Socket<'a, 'b>> for IcmpSocket<'a, 'b> {
fn into(self) -> Socket<'a, 'b> {
impl<'a> Into<Socket<'a>> for IcmpSocket<'a> {
fn into(self) -> Socket<'a> {
Socket::Icmp(self)
}
}
Expand All @@ -467,12 +467,12 @@ mod tests_common {
pub use crate::wire::IpAddress;
pub use super::*;

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

pub fn socket(rx_buffer: IcmpSocketBuffer<'static, 'static>,
tx_buffer: IcmpSocketBuffer<'static, 'static>) -> IcmpSocket<'static, 'static> {
pub fn socket(rx_buffer: IcmpSocketBuffer<'static>,
tx_buffer: IcmpSocketBuffer<'static>) -> IcmpSocket<'static> {
IcmpSocket::new(rx_buffer, tx_buffer)
}

Expand Down
28 changes: 14 additions & 14 deletions src/socket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@ pub(crate) enum PollAt {
/// [AnySocket]: trait.AnySocket.html
/// [SocketSet::get]: struct.SocketSet.html#method.get
#[derive(Debug)]
pub enum Socket<'a, 'b: 'a> {
pub enum Socket<'a> {
#[cfg(feature = "socket-raw")]
Raw(RawSocket<'a, 'b>),
Raw(RawSocket<'a>),
#[cfg(all(feature = "socket-icmp", any(feature = "proto-ipv4", feature = "proto-ipv6")))]
Icmp(IcmpSocket<'a, 'b>),
Icmp(IcmpSocket<'a>),
#[cfg(feature = "socket-udp")]
Udp(UdpSocket<'a, 'b>),
Udp(UdpSocket<'a>),
#[cfg(feature = "socket-tcp")]
Tcp(TcpSocket<'a>),
#[doc(hidden)]
__Nonexhaustive(PhantomData<(&'a (), &'b ())>)
__Nonexhaustive(PhantomData<&'a ()>)
}

macro_rules! dispatch_socket {
Expand All @@ -117,7 +117,7 @@ macro_rules! dispatch_socket {
};
}

impl<'a, 'b> Socket<'a, 'b> {
impl<'a> Socket<'a> {
/// Return the socket handle.
#[inline]
pub fn handle(&self) -> SocketHandle {
Expand All @@ -137,22 +137,22 @@ impl<'a, 'b> Socket<'a, 'b> {
}
}

impl<'a, 'b> SocketSession for Socket<'a, 'b> {
impl<'a> SocketSession for Socket<'a> {
fn finish(&mut self) {
dispatch_socket!(mut self, |socket| socket.finish())
}
}

/// A conversion trait for network sockets.
pub trait AnySocket<'a, 'b>: SocketSession + Sized {
fn downcast<'c>(socket_ref: SocketRef<'c, Socket<'a, 'b>>) ->
pub trait AnySocket<'a>: SocketSession + Sized {
fn downcast<'c>(socket_ref: SocketRef<'c, Socket<'a>>) ->
Option<SocketRef<'c, Self>>;
}

macro_rules! from_socket {
($socket:ty, $variant:ident) => {
impl<'a, 'b> AnySocket<'a, 'b> for $socket {
fn downcast<'c>(ref_: SocketRef<'c, Socket<'a, 'b>>) ->
impl<'a> AnySocket<'a> for $socket {
fn downcast<'c>(ref_: SocketRef<'c, Socket<'a>>) ->
Option<SocketRef<'c, Self>> {
match SocketRef::into_inner(ref_) {
&mut Socket::$variant(ref mut socket) => Some(SocketRef::new(socket)),
Expand All @@ -164,10 +164,10 @@ macro_rules! from_socket {
}

#[cfg(feature = "socket-raw")]
from_socket!(RawSocket<'a, 'b>, Raw);
from_socket!(RawSocket<'a>, Raw);
#[cfg(all(feature = "socket-icmp", any(feature = "proto-ipv4", feature = "proto-ipv6")))]
from_socket!(IcmpSocket<'a, 'b>, Icmp);
from_socket!(IcmpSocket<'a>, Icmp);
#[cfg(feature = "socket-udp")]
from_socket!(UdpSocket<'a, 'b>, Udp);
from_socket!(UdpSocket<'a>, Udp);
#[cfg(feature = "socket-tcp")]
from_socket!(TcpSocket<'a>, Tcp);
32 changes: 16 additions & 16 deletions src/socket/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,31 @@ use crate::wire::{Ipv6Repr, Ipv6Packet};
pub type RawPacketMetadata = PacketMetadata<()>;

/// A UDP packet ring buffer.
pub type RawSocketBuffer<'a, 'b> = PacketBuffer<'a, 'b, ()>;
pub type RawSocketBuffer<'a> = PacketBuffer<'a, ()>;

/// A raw IP socket.
///
/// A raw socket is bound to a specific IP protocol, and owns
/// transmit and receive packet buffers.
#[derive(Debug)]
pub struct RawSocket<'a, 'b: 'a> {
pub struct RawSocket<'a> {
pub(crate) meta: SocketMeta,
ip_version: IpVersion,
ip_protocol: IpProtocol,
rx_buffer: RawSocketBuffer<'a, 'b>,
tx_buffer: RawSocketBuffer<'a, 'b>,
rx_buffer: RawSocketBuffer<'a>,
tx_buffer: RawSocketBuffer<'a>,
#[cfg(feature = "async")]
rx_waker: WakerRegistration,
#[cfg(feature = "async")]
tx_waker: WakerRegistration,
}

impl<'a, 'b> RawSocket<'a, 'b> {
impl<'a> RawSocket<'a> {
/// Create a raw IP socket bound to the given IP version and datagram protocol,
/// with the given buffers.
pub fn new(ip_version: IpVersion, ip_protocol: IpProtocol,
rx_buffer: RawSocketBuffer<'a, 'b>,
tx_buffer: RawSocketBuffer<'a, 'b>) -> RawSocket<'a, 'b> {
rx_buffer: RawSocketBuffer<'a>,
tx_buffer: RawSocketBuffer<'a>) -> RawSocket<'a> {
RawSocket {
meta: SocketMeta::default(),
ip_version,
Expand Down Expand Up @@ -297,8 +297,8 @@ impl<'a, 'b> RawSocket<'a, 'b> {
}
}

impl<'a, 'b> Into<Socket<'a, 'b>> for RawSocket<'a, 'b> {
fn into(self) -> Socket<'a, 'b> {
impl<'a> Into<Socket<'a>> for RawSocket<'a> {
fn into(self) -> Socket<'a> {
Socket::Raw(self)
}
}
Expand All @@ -312,17 +312,17 @@ mod test {
use crate::wire::{Ipv6Address, Ipv6Repr};
use super::*;

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

#[cfg(feature = "proto-ipv4")]
mod ipv4_locals {
use super::*;

pub fn socket(rx_buffer: RawSocketBuffer<'static, 'static>,
tx_buffer: RawSocketBuffer<'static, 'static>)
-> RawSocket<'static, 'static> {
pub fn socket(rx_buffer: RawSocketBuffer<'static>,
tx_buffer: RawSocketBuffer<'static>)
-> RawSocket<'static> {
RawSocket::new(IpVersion::Ipv4, IpProtocol::Unknown(IP_PROTO),
rx_buffer, tx_buffer)
}
Expand Down Expand Up @@ -352,9 +352,9 @@ mod test {
mod ipv6_locals {
use super::*;

pub fn socket(rx_buffer: RawSocketBuffer<'static, 'static>,
tx_buffer: RawSocketBuffer<'static, 'static>)
-> RawSocket<'static, 'static> {
pub fn socket(rx_buffer: RawSocketBuffer<'static>,
tx_buffer: RawSocketBuffer<'static>)
-> RawSocket<'static> {
RawSocket::new(IpVersion::Ipv6, IpProtocol::Unknown(IP_PROTO),
rx_buffer, tx_buffer)
}
Expand Down
6 changes: 3 additions & 3 deletions src/socket/ref_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ pub trait Session {
}

#[cfg(feature = "socket-raw")]
impl<'a, 'b> Session for RawSocket<'a, 'b> {}
impl<'a> Session for RawSocket<'a> {}
#[cfg(all(feature = "socket-icmp", any(feature = "proto-ipv4", feature = "proto-ipv6")))]
impl<'a, 'b> Session for IcmpSocket<'a, 'b> {}
impl<'a> Session for IcmpSocket<'a> {}
#[cfg(feature = "socket-udp")]
impl<'a, 'b> Session for UdpSocket<'a, 'b> {}
impl<'a> Session for UdpSocket<'a> {}
#[cfg(feature = "socket-tcp")]
impl<'a> Session for TcpSocket<'a> {}

Expand Down
46 changes: 23 additions & 23 deletions src/socket/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::socket::TcpState;
/// The only reason this struct is public is to allow the socket set storage
/// to be allocated externally.
#[derive(Debug)]
pub struct Item<'a, 'b: 'a> {
socket: Socket<'a, 'b>,
pub struct Item<'a> {
socket: Socket<'a>,
refs: usize
}

Expand All @@ -27,16 +27,16 @@ impl fmt::Display for Handle {

/// An extensible set of sockets.
///
/// The lifetimes `'b` and `'c` are used when storing a `Socket<'b, 'c>`.
/// The lifetime `'b` is used when storing a `Socket<'b>`.
#[derive(Debug)]
pub struct Set<'a, 'b: 'a, 'c: 'a + 'b> {
sockets: ManagedSlice<'a, Option<Item<'b, 'c>>>
pub struct Set<'a, 'b: 'a> {
sockets: ManagedSlice<'a, Option<Item<'b>>>
}

impl<'a, 'b: 'a, 'c: 'a + 'b> Set<'a, 'b, 'c> {
impl<'a, 'b: 'a> Set<'a, 'b> {
/// Create a socket set using the provided storage.
pub fn new<SocketsT>(sockets: SocketsT) -> Set<'a, 'b, 'c>
where SocketsT: Into<ManagedSlice<'a, Option<Item<'b, 'c>>>> {
pub fn new<SocketsT>(sockets: SocketsT) -> Set<'a, 'b>
where SocketsT: Into<ManagedSlice<'a, Option<Item<'b>>>> {
let sockets = sockets.into();
Set { sockets }
}
Expand All @@ -46,10 +46,10 @@ impl<'a, 'b: 'a, 'c: 'a + 'b> Set<'a, 'b, 'c> {
/// # Panics
/// This function panics if the storage is fixed-size (not a `Vec`) and is full.
pub fn add<T>(&mut self, socket: T) -> Handle
where T: Into<Socket<'b, 'c>>
where T: Into<Socket<'b>>
{
fn put<'b, 'c>(index: usize, slot: &mut Option<Item<'b, 'c>>,
mut socket: Socket<'b, 'c>) -> Handle {
fn put<'b>(index: usize, slot: &mut Option<Item<'b>>,
mut socket: Socket<'b>) -> Handle {
net_trace!("[{}]: adding", index);
let handle = Handle(index);
socket.meta_mut().handle = handle;
Expand Down Expand Up @@ -83,7 +83,7 @@ impl<'a, 'b: 'a, 'c: 'a + 'b> Set<'a, 'b, 'c> {
/// # Panics
/// This function may panic if the handle does not belong to this socket set
/// or the socket has the wrong type.
pub fn get<T: AnySocket<'b, 'c>>(&mut self, handle: Handle) -> SocketRef<T> {
pub fn get<T: AnySocket<'b>>(&mut self, handle: Handle) -> SocketRef<T> {
match self.sockets[handle.0].as_mut() {
Some(item) => {
T::downcast(SocketRef::new(&mut item.socket))
Expand All @@ -97,7 +97,7 @@ impl<'a, 'b: 'a, 'c: 'a + 'b> Set<'a, 'b, 'c> {
///
/// # Panics
/// This function may panic if the handle does not belong to this socket set.
pub fn remove(&mut self, handle: Handle) -> Socket<'b, 'c> {
pub fn remove(&mut self, handle: Handle) -> Socket<'b> {
net_trace!("[{}]: removing", handle.0);
match self.sockets[handle.0].take() {
Some(item) => item.socket,
Expand Down Expand Up @@ -166,12 +166,12 @@ impl<'a, 'b: 'a, 'c: 'a + 'b> Set<'a, 'b, 'c> {
}

/// Iterate every socket in this set.
pub fn iter<'d>(&'d self) -> Iter<'d, 'b, 'c> {
pub fn iter<'d>(&'d self) -> Iter<'d, 'b> {
Iter { lower: self.sockets.iter() }
}

/// Iterate every socket in this set, as SocketRef.
pub fn iter_mut<'d>(&'d mut self) -> IterMut<'d, 'b, 'c> {
pub fn iter_mut<'d>(&'d mut self) -> IterMut<'d, 'b> {
IterMut { lower: self.sockets.iter_mut() }
}
}
Expand All @@ -180,12 +180,12 @@ impl<'a, 'b: 'a, 'c: 'a + 'b> Set<'a, 'b, 'c> {
///
/// This struct is created by the [iter](struct.SocketSet.html#method.iter)
/// on [socket sets](struct.SocketSet.html).
pub struct Iter<'a, 'b: 'a, 'c: 'a + 'b> {
lower: slice::Iter<'a, Option<Item<'b, 'c>>>
pub struct Iter<'a, 'b: 'a> {
lower: slice::Iter<'a, Option<Item<'b>>>
}

impl<'a, 'b: 'a, 'c: 'a + 'b> Iterator for Iter<'a, 'b, 'c> {
type Item = &'a Socket<'b, 'c>;
impl<'a, 'b: 'a> Iterator for Iter<'a, 'b> {
type Item = &'a Socket<'b>;

fn next(&mut self) -> Option<Self::Item> {
while let Some(item_opt) = self.lower.next() {
Expand All @@ -201,12 +201,12 @@ impl<'a, 'b: 'a, 'c: 'a + 'b> Iterator for Iter<'a, 'b, 'c> {
///
/// This struct is created by the [iter_mut](struct.SocketSet.html#method.iter_mut)
/// on [socket sets](struct.SocketSet.html).
pub struct IterMut<'a, 'b: 'a, 'c: 'a + 'b> {
lower: slice::IterMut<'a, Option<Item<'b, 'c>>>,
pub struct IterMut<'a, 'b: 'a> {
lower: slice::IterMut<'a, Option<Item<'b>>>,
}

impl<'a, 'b: 'a, 'c: 'a + 'b> Iterator for IterMut<'a, 'b, 'c> {
type Item = SocketRef<'a, Socket<'b, 'c>>;
impl<'a, 'b: 'a> Iterator for IterMut<'a, 'b> {
type Item = SocketRef<'a, Socket<'b>>;

fn next(&mut self) -> Option<Self::Item> {
while let Some(item_opt) = self.lower.next() {
Expand Down
4 changes: 2 additions & 2 deletions src/socket/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1943,8 +1943,8 @@ impl<'a> TcpSocket<'a> {
}
}

impl<'a, 'b> Into<Socket<'a, 'b>> for TcpSocket<'a> {
fn into(self) -> Socket<'a, 'b> {
impl<'a> Into<Socket<'a>> for TcpSocket<'a> {
fn into(self) -> Socket<'a> {
Socket::Tcp(self)
}
}
Expand Down
Loading