Skip to content

Commit d242ff4

Browse files
committed
socket/set: remove reference counting.
It is never used in practice, so it's not worth the complexity and the extra RAM usage.
1 parent 9a2093e commit d242ff4

File tree

2 files changed

+3
-74
lines changed

2 files changed

+3
-74
lines changed

src/iface/interface.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ impl<'a, DeviceT> Interface<'a, DeviceT>
469469
where
470470
DeviceT: for<'d> Device<'d>,
471471
{
472-
/// Add a socket to the interface with the reference count 1, and return its handle.
472+
/// Add a socket to the interface, and return its handle.
473473
///
474474
/// # Panics
475475
/// This function panics if the storage is fixed-size (not a `Vec`) and is full.

src/socket/set.rs

Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use core::{fmt, slice};
22
use managed::ManagedSlice;
33

4-
#[cfg(feature = "socket-tcp")]
5-
use crate::socket::TcpState;
64
use crate::socket::{AnySocket, Socket};
75

86
/// An item of a socket set.
@@ -12,7 +10,6 @@ use crate::socket::{AnySocket, Socket};
1210
#[derive(Debug)]
1311
pub struct Item<'a> {
1412
socket: Socket<'a>,
15-
refs: usize,
1613
}
1714

1815
/// A handle, identifying a socket in a set.
@@ -44,7 +41,7 @@ impl<'a> Set<'a> {
4441
Set { sockets }
4542
}
4643

47-
/// Add a socket to the set with the reference count 1, and return its handle.
44+
/// Add a socket to the set, and return its handle.
4845
///
4946
/// # Panics
5047
/// This function panics if the storage is fixed-size (not a `Vec`) and is full.
@@ -56,7 +53,7 @@ impl<'a> Set<'a> {
5653
net_trace!("[{}]: adding", index);
5754
let handle = Handle(index);
5855
socket.meta_mut().handle = handle;
59-
*slot = Some(Item { socket, refs: 1 });
56+
*slot = Some(Item { socket });
6057
handle
6158
}
6259

@@ -105,74 +102,6 @@ impl<'a> Set<'a> {
105102
}
106103
}
107104

108-
/// Increase reference count by 1.
109-
///
110-
/// # Panics
111-
/// This function may panic if the handle does not belong to this socket set.
112-
pub fn retain(&mut self, handle: Handle) {
113-
self.sockets[handle.0]
114-
.as_mut()
115-
.expect("handle does not refer to a valid socket")
116-
.refs += 1
117-
}
118-
119-
/// Decrease reference count by 1.
120-
///
121-
/// # Panics
122-
/// This function may panic if the handle does not belong to this socket set,
123-
/// or if the reference count is already zero.
124-
pub fn release(&mut self, handle: Handle) {
125-
let refs = &mut self.sockets[handle.0]
126-
.as_mut()
127-
.expect("handle does not refer to a valid socket")
128-
.refs;
129-
if *refs == 0 {
130-
panic!("decreasing reference count past zero")
131-
}
132-
*refs -= 1
133-
}
134-
135-
/// Prune the sockets in this set.
136-
///
137-
/// Pruning affects sockets with reference count 0. Open sockets are closed.
138-
/// Closed sockets are removed and dropped.
139-
pub fn prune(&mut self) {
140-
for (index, item) in self.sockets.iter_mut().enumerate() {
141-
let mut may_remove = false;
142-
if let Some(Item {
143-
refs: 0,
144-
ref mut socket,
145-
}) = *item
146-
{
147-
match *socket {
148-
#[cfg(feature = "socket-raw")]
149-
Socket::Raw(_) => may_remove = true,
150-
#[cfg(all(
151-
feature = "socket-icmp",
152-
any(feature = "proto-ipv4", feature = "proto-ipv6")
153-
))]
154-
Socket::Icmp(_) => may_remove = true,
155-
#[cfg(feature = "socket-udp")]
156-
Socket::Udp(_) => may_remove = true,
157-
#[cfg(feature = "socket-tcp")]
158-
Socket::Tcp(ref mut socket) => {
159-
if socket.state() == TcpState::Closed {
160-
may_remove = true
161-
} else {
162-
socket.close()
163-
}
164-
}
165-
#[cfg(feature = "socket-dhcpv4")]
166-
Socket::Dhcpv4(_) => may_remove = true,
167-
}
168-
}
169-
if may_remove {
170-
net_trace!("[{}]: pruning", index);
171-
*item = None
172-
}
173-
}
174-
}
175-
176105
/// Iterate every socket in this set.
177106
pub fn iter<'d>(&'d self) -> Iter<'d, 'a> {
178107
Iter {

0 commit comments

Comments
 (0)