-
Notifications
You must be signed in to change notification settings - Fork 478
Abstract SocketSet to AnySocketSet trait #944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
I'm concerned about the extra complexity caused by having to pass the generic param through everywhere. What's the intended use case of the SocketSet trait? There are pending possible improvements to SocketSet. For example make packet dispatch more efficient than O(n). However, this makes the trait interface only capable of iteration, which locks us into O(n) more. |
I am considering customizing the socket set, the addition of socket, query and iteration are closely related, such as the order of socket, etc. I have some cases such as the coexistence of any port and bound port, and tcp and udp should be in different sets. Zone rapid retrieval and iteration, etc., they rely more or less on the order of socket in the set. If you want to complete some complex tasks, it is necessary to do complex processing work in the core dispatcher, and add a custom socket set trait to meet the upper dispatching requirements. I am encapsulating the upper application network protocol stack, and I have been hindered by the socket set to varying degrees. This PR will alleviate a lot of effects, which is also my original intention to do something in rust-managed. |
Anyway, if the above arguments are agreed, then this socket set trait should define other public api other than iteration, which is worth considering. So what do you think you need to consider about this PR? |
7abdbcd
to
ea31e07
Compare
@Dirbaio would there be any interest in merging a |
Something like this maybe ? pub trait SocketSet {
fn for_each<R, F>(&self, f: F) -> Option<R>
where
F: FnMut(&SocketStorage<'_>) -> ControlFlow<R>;
fn for_each_mut<R, F>(&mut self, f: &mut F) -> Option<R>
where
F: FnMut(&mut SocketStorage<'_>) -> ControlFlow<R>;
fn for_each_accepting<R, F>(&self, ip: &IpRepr, f: &mut F) -> Option<R>
where
F: FnMut(&SocketStorage<'_>) -> ControlFlow<R>
{
let _ = ip;
self.for_each(f)
}
fn for_each_accepting<R, F>(&mut self, ip: &IpRepr, f: &mut F) -> Option<R>
where
F: FnMut(&mut SocketStorage<'_>) -> ControlFlow<R>
{
let _ = ip;
self.for_each_mut(f)
}
}
impl SocketSet for [SocketStorage<'_>] {
fn for_each<R, F>(&self, f: F) -> Option<R>
where
F: FnMut(&SocketStorage<'_>) -> ControlFlow<R>
{
for storage in self {
match f(storage) {
ControlFlow::Break(result) => return Some(result),
ControlFlow::Continue(()) => continue,
}
}
None
}
fn for_each_mut<R, F>(&mut self, f: &mut F) -> Option<R>
where
F: FnMut(&mut SocketStorage<'_>) -> ControlFlow<R>
{
for storage in self {
match f(storage) {
ControlFlow::Break(result) => return Some(result),
ControlFlow::Continue(()) => continue,
}
}
None
}
} |
No description provided.