Skip to content

Commit 11255a8

Browse files
committed
Simplify Socket lifetimes
1 parent 923d637 commit 11255a8

File tree

10 files changed

+91
-92
lines changed

10 files changed

+91
-92
lines changed

src/dhcp/clientv4.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ impl Client {
9494
/// Instant::now()
9595
/// );
9696
/// ```
97-
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
98-
where 'b: 'c,
97+
pub fn new<'a, 'b>(sockets: &mut SocketSet<'a, 'b>, rx_buffer: RawSocketBuffer<'b>, tx_buffer: RawSocketBuffer<'b>, now: Instant) -> Self
9998
{
10099
let raw_socket = RawSocket::new(IpVersion::Ipv4, IpProtocol::Udp, rx_buffer, tx_buffer);
101100
let raw_handle = sockets.add(raw_socket);

src/iface/ethernet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1727,7 +1727,7 @@ mod test {
17271727
use super::{EthernetPacket, IpPacket};
17281728

17291729
fn create_loopback<'a, 'b, 'c>() -> (EthernetInterface<'static, 'b, 'c, Loopback>,
1730-
SocketSet<'static, 'a, 'b>) {
1730+
SocketSet<'static, 'a>) {
17311731
// Create a basic device
17321732
let device = Loopback::new();
17331733
let ip_addrs = [

src/socket/icmp.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl Default for Endpoint {
4646
pub type IcmpPacketMetadata = PacketMetadata<IpAddress>;
4747

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

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

75-
impl<'a, 'b> IcmpSocket<'a, 'b> {
75+
impl<'a> IcmpSocket<'a> {
7676
/// Create an ICMP socket with the given buffers.
77-
pub fn new(rx_buffer: IcmpSocketBuffer<'a, 'b>,
78-
tx_buffer: IcmpSocketBuffer<'a, 'b>) -> IcmpSocket<'a, 'b> {
77+
pub fn new(rx_buffer: IcmpSocketBuffer<'a>,
78+
tx_buffer: IcmpSocketBuffer<'a>) -> IcmpSocket<'a> {
7979
IcmpSocket {
8080
meta: SocketMeta::default(),
8181
rx_buffer: rx_buffer,
@@ -455,8 +455,8 @@ impl<'a, 'b> IcmpSocket<'a, 'b> {
455455
}
456456
}
457457

458-
impl<'a, 'b> Into<Socket<'a, 'b>> for IcmpSocket<'a, 'b> {
459-
fn into(self) -> Socket<'a, 'b> {
458+
impl<'a> Into<Socket<'a>> for IcmpSocket<'a> {
459+
fn into(self) -> Socket<'a> {
460460
Socket::Icmp(self)
461461
}
462462
}
@@ -467,12 +467,12 @@ mod tests_common {
467467
pub use crate::wire::IpAddress;
468468
pub use super::*;
469469

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

474-
pub fn socket(rx_buffer: IcmpSocketBuffer<'static, 'static>,
475-
tx_buffer: IcmpSocketBuffer<'static, 'static>) -> IcmpSocket<'static, 'static> {
474+
pub fn socket(rx_buffer: IcmpSocketBuffer<'static>,
475+
tx_buffer: IcmpSocketBuffer<'static>) -> IcmpSocket<'static> {
476476
IcmpSocket::new(rx_buffer, tx_buffer)
477477
}
478478

src/socket/mod.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,17 @@ pub(crate) enum PollAt {
8282
/// [AnySocket]: trait.AnySocket.html
8383
/// [SocketSet::get]: struct.SocketSet.html#method.get
8484
#[derive(Debug)]
85-
pub enum Socket<'a, 'b: 'a> {
85+
pub enum Socket<'a> {
8686
#[cfg(feature = "socket-raw")]
87-
Raw(RawSocket<'a, 'b>),
87+
Raw(RawSocket<'a>),
8888
#[cfg(all(feature = "socket-icmp", any(feature = "proto-ipv4", feature = "proto-ipv6")))]
89-
Icmp(IcmpSocket<'a, 'b>),
89+
Icmp(IcmpSocket<'a>),
9090
#[cfg(feature = "socket-udp")]
91-
Udp(UdpSocket<'a, 'b>),
91+
Udp(UdpSocket<'a>),
9292
#[cfg(feature = "socket-tcp")]
9393
Tcp(TcpSocket<'a>),
9494
#[doc(hidden)]
95-
__Nonexhaustive(PhantomData<(&'a (), &'b ())>)
95+
__Nonexhaustive(PhantomData<&'a ()>)
9696
}
9797

9898
macro_rules! dispatch_socket {
@@ -117,7 +117,7 @@ macro_rules! dispatch_socket {
117117
};
118118
}
119119

120-
impl<'a, 'b> Socket<'a, 'b> {
120+
impl<'a> Socket<'a> {
121121
/// Return the socket handle.
122122
#[inline]
123123
pub fn handle(&self) -> SocketHandle {
@@ -137,22 +137,22 @@ impl<'a, 'b> Socket<'a, 'b> {
137137
}
138138
}
139139

140-
impl<'a, 'b> SocketSession for Socket<'a, 'b> {
140+
impl<'a> SocketSession for Socket<'a> {
141141
fn finish(&mut self) {
142142
dispatch_socket!(mut self, |socket| socket.finish())
143143
}
144144
}
145145

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

152152
macro_rules! from_socket {
153153
($socket:ty, $variant:ident) => {
154-
impl<'a, 'b> AnySocket<'a, 'b> for $socket {
155-
fn downcast<'c>(ref_: SocketRef<'c, Socket<'a, 'b>>) ->
154+
impl<'a> AnySocket<'a> for $socket {
155+
fn downcast<'c>(ref_: SocketRef<'c, Socket<'a>>) ->
156156
Option<SocketRef<'c, Self>> {
157157
match SocketRef::into_inner(ref_) {
158158
&mut Socket::$variant(ref mut socket) => Some(SocketRef::new(socket)),
@@ -164,10 +164,10 @@ macro_rules! from_socket {
164164
}
165165

166166
#[cfg(feature = "socket-raw")]
167-
from_socket!(RawSocket<'a, 'b>, Raw);
167+
from_socket!(RawSocket<'a>, Raw);
168168
#[cfg(all(feature = "socket-icmp", any(feature = "proto-ipv4", feature = "proto-ipv6")))]
169-
from_socket!(IcmpSocket<'a, 'b>, Icmp);
169+
from_socket!(IcmpSocket<'a>, Icmp);
170170
#[cfg(feature = "socket-udp")]
171-
from_socket!(UdpSocket<'a, 'b>, Udp);
171+
from_socket!(UdpSocket<'a>, Udp);
172172
#[cfg(feature = "socket-tcp")]
173173
from_socket!(TcpSocket<'a>, Tcp);

src/socket/raw.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,31 @@ use crate::wire::{Ipv6Repr, Ipv6Packet};
1919
pub type RawPacketMetadata = PacketMetadata<()>;
2020

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

2424
/// A raw IP socket.
2525
///
2626
/// A raw socket is bound to a specific IP protocol, and owns
2727
/// transmit and receive packet buffers.
2828
#[derive(Debug)]
29-
pub struct RawSocket<'a, 'b: 'a> {
29+
pub struct RawSocket<'a> {
3030
pub(crate) meta: SocketMeta,
3131
ip_version: IpVersion,
3232
ip_protocol: IpProtocol,
33-
rx_buffer: RawSocketBuffer<'a, 'b>,
34-
tx_buffer: RawSocketBuffer<'a, 'b>,
33+
rx_buffer: RawSocketBuffer<'a>,
34+
tx_buffer: RawSocketBuffer<'a>,
3535
#[cfg(feature = "async")]
3636
rx_waker: WakerRegistration,
3737
#[cfg(feature = "async")]
3838
tx_waker: WakerRegistration,
3939
}
4040

41-
impl<'a, 'b> RawSocket<'a, 'b> {
41+
impl<'a> RawSocket<'a> {
4242
/// Create a raw IP socket bound to the given IP version and datagram protocol,
4343
/// with the given buffers.
4444
pub fn new(ip_version: IpVersion, ip_protocol: IpProtocol,
45-
rx_buffer: RawSocketBuffer<'a, 'b>,
46-
tx_buffer: RawSocketBuffer<'a, 'b>) -> RawSocket<'a, 'b> {
45+
rx_buffer: RawSocketBuffer<'a>,
46+
tx_buffer: RawSocketBuffer<'a>) -> RawSocket<'a> {
4747
RawSocket {
4848
meta: SocketMeta::default(),
4949
ip_version,
@@ -297,8 +297,8 @@ impl<'a, 'b> RawSocket<'a, 'b> {
297297
}
298298
}
299299

300-
impl<'a, 'b> Into<Socket<'a, 'b>> for RawSocket<'a, 'b> {
301-
fn into(self) -> Socket<'a, 'b> {
300+
impl<'a> Into<Socket<'a>> for RawSocket<'a> {
301+
fn into(self) -> Socket<'a> {
302302
Socket::Raw(self)
303303
}
304304
}
@@ -312,17 +312,17 @@ mod test {
312312
use crate::wire::{Ipv6Address, Ipv6Repr};
313313
use super::*;
314314

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

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

323-
pub fn socket(rx_buffer: RawSocketBuffer<'static, 'static>,
324-
tx_buffer: RawSocketBuffer<'static, 'static>)
325-
-> RawSocket<'static, 'static> {
323+
pub fn socket(rx_buffer: RawSocketBuffer<'static>,
324+
tx_buffer: RawSocketBuffer<'static>)
325+
-> RawSocket<'static> {
326326
RawSocket::new(IpVersion::Ipv4, IpProtocol::Unknown(IP_PROTO),
327327
rx_buffer, tx_buffer)
328328
}
@@ -352,9 +352,9 @@ mod test {
352352
mod ipv6_locals {
353353
use super::*;
354354

355-
pub fn socket(rx_buffer: RawSocketBuffer<'static, 'static>,
356-
tx_buffer: RawSocketBuffer<'static, 'static>)
357-
-> RawSocket<'static, 'static> {
355+
pub fn socket(rx_buffer: RawSocketBuffer<'static>,
356+
tx_buffer: RawSocketBuffer<'static>)
357+
-> RawSocket<'static> {
358358
RawSocket::new(IpVersion::Ipv6, IpProtocol::Unknown(IP_PROTO),
359359
rx_buffer, tx_buffer)
360360
}

src/socket/ref_.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ pub trait Session {
2020
}
2121

2222
#[cfg(feature = "socket-raw")]
23-
impl<'a, 'b> Session for RawSocket<'a, 'b> {}
23+
impl<'a> Session for RawSocket<'a> {}
2424
#[cfg(all(feature = "socket-icmp", any(feature = "proto-ipv4", feature = "proto-ipv6")))]
25-
impl<'a, 'b> Session for IcmpSocket<'a, 'b> {}
25+
impl<'a> Session for IcmpSocket<'a> {}
2626
#[cfg(feature = "socket-udp")]
27-
impl<'a, 'b> Session for UdpSocket<'a, 'b> {}
27+
impl<'a> Session for UdpSocket<'a> {}
2828
#[cfg(feature = "socket-tcp")]
2929
impl<'a> Session for TcpSocket<'a> {}
3030

src/socket/set.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use crate::socket::TcpState;
1010
/// The only reason this struct is public is to allow the socket set storage
1111
/// to be allocated externally.
1212
#[derive(Debug)]
13-
pub struct Item<'a, 'b: 'a> {
14-
socket: Socket<'a, 'b>,
13+
pub struct Item<'a> {
14+
socket: Socket<'a>,
1515
refs: usize
1616
}
1717

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

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

36-
impl<'a, 'b: 'a, 'c: 'a + 'b> Set<'a, 'b, 'c> {
36+
impl<'a, 'b: 'a> Set<'a, 'b> {
3737
/// Create a socket set using the provided storage.
38-
pub fn new<SocketsT>(sockets: SocketsT) -> Set<'a, 'b, 'c>
39-
where SocketsT: Into<ManagedSlice<'a, Option<Item<'b, 'c>>>> {
38+
pub fn new<SocketsT>(sockets: SocketsT) -> Set<'a, 'b>
39+
where SocketsT: Into<ManagedSlice<'a, Option<Item<'b>>>> {
4040
let sockets = sockets.into();
4141
Set { sockets }
4242
}
@@ -46,10 +46,10 @@ impl<'a, 'b: 'a, 'c: 'a + 'b> Set<'a, 'b, 'c> {
4646
/// # Panics
4747
/// This function panics if the storage is fixed-size (not a `Vec`) and is full.
4848
pub fn add<T>(&mut self, socket: T) -> Handle
49-
where T: Into<Socket<'b, 'c>>
49+
where T: Into<Socket<'b>>
5050
{
51-
fn put<'b, 'c>(index: usize, slot: &mut Option<Item<'b, 'c>>,
52-
mut socket: Socket<'b, 'c>) -> Handle {
51+
fn put<'b>(index: usize, slot: &mut Option<Item<'b>>,
52+
mut socket: Socket<'b>) -> Handle {
5353
net_trace!("[{}]: adding", index);
5454
let handle = Handle(index);
5555
socket.meta_mut().handle = handle;
@@ -83,7 +83,7 @@ impl<'a, 'b: 'a, 'c: 'a + 'b> Set<'a, 'b, 'c> {
8383
/// # Panics
8484
/// This function may panic if the handle does not belong to this socket set
8585
/// or the socket has the wrong type.
86-
pub fn get<T: AnySocket<'b, 'c>>(&mut self, handle: Handle) -> SocketRef<T> {
86+
pub fn get<T: AnySocket<'b>>(&mut self, handle: Handle) -> SocketRef<T> {
8787
match self.sockets[handle.0].as_mut() {
8888
Some(item) => {
8989
T::downcast(SocketRef::new(&mut item.socket))
@@ -97,7 +97,7 @@ impl<'a, 'b: 'a, 'c: 'a + 'b> Set<'a, 'b, 'c> {
9797
///
9898
/// # Panics
9999
/// This function may panic if the handle does not belong to this socket set.
100-
pub fn remove(&mut self, handle: Handle) -> Socket<'b, 'c> {
100+
pub fn remove(&mut self, handle: Handle) -> Socket<'b> {
101101
net_trace!("[{}]: removing", handle.0);
102102
match self.sockets[handle.0].take() {
103103
Some(item) => item.socket,
@@ -166,12 +166,12 @@ impl<'a, 'b: 'a, 'c: 'a + 'b> Set<'a, 'b, 'c> {
166166
}
167167

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

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

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

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

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

211211
fn next(&mut self) -> Option<Self::Item> {
212212
while let Some(item_opt) = self.lower.next() {

src/socket/tcp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,8 +1943,8 @@ impl<'a> TcpSocket<'a> {
19431943
}
19441944
}
19451945

1946-
impl<'a, 'b> Into<Socket<'a, 'b>> for TcpSocket<'a> {
1947-
fn into(self) -> Socket<'a, 'b> {
1946+
impl<'a> Into<Socket<'a>> for TcpSocket<'a> {
1947+
fn into(self) -> Socket<'a> {
19481948
Socket::Tcp(self)
19491949
}
19501950
}

0 commit comments

Comments
 (0)