Skip to main content

ibverbs_rs/multi_channel/
polling_scope.rs

1use crate::channel::{PollingScope, ScopeError};
2use crate::ibverbs::protection_domain::ProtectionDomain;
3use crate::multi_channel::MultiChannel;
4
5impl MultiChannel {
6    /// Opens a polling scope that automatically polls all outstanding work requests when it ends.
7    ///
8    /// See [`Channel::scope`](crate::channel::Channel::scope) for details on the scoping mechanism.
9    pub fn scope<'env, F, T, E>(&'env mut self, f: F) -> Result<T, ScopeError<E>>
10    where
11        F: for<'scope> FnOnce(&mut PollingScope<'scope, 'env, MultiChannel>) -> Result<T, E>,
12    {
13        PollingScope::run(self, f)
14    }
15
16    /// Opens a polling scope that enforces manual polling of all work requests.
17    ///
18    /// See [`Channel::manual_scope`](crate::channel::Channel::manual_scope) for details.
19    pub fn manual_scope<'env, F, T, E>(&'env mut self, f: F) -> Result<T, E>
20    where
21        F: for<'scope> FnOnce(&mut PollingScope<'scope, 'env, MultiChannel>) -> Result<T, E>,
22    {
23        PollingScope::run_manual(self, f)
24    }
25}
26
27impl<'scope, 'env> PollingScope<'scope, 'env, MultiChannel> {
28    /// Returns a reference to the shared [`ProtectionDomain`].
29    pub fn pd(&self) -> &ProtectionDomain {
30        self.inner.pd()
31    }
32
33    /// Returns the number of channels in the underlying [`MultiChannel`].
34    pub fn num_channels(&self) -> usize {
35        self.inner.channels.len()
36    }
37}