Skip to main content

ibverbs_rs/network/ops/
channel_ops.rs

1use crate::channel::TransportResult;
2use crate::channel::{PendingWork, PollingScope, ScopedPendingWork};
3use crate::ibverbs::error::IbvResult;
4use crate::ibverbs::work::WorkSuccess;
5use crate::multi_channel::{
6    PeerReadWorkRequest, PeerReceiveWorkRequest, PeerSendWorkRequest, PeerWriteWorkRequest,
7};
8use crate::network::Node;
9
10impl<'scope, 'env> PollingScope<'scope, 'env, Node> {
11    /// Posts a send to the work request's target peer, returning a handle for manual polling.
12    pub fn post_send(
13        &mut self,
14        wr: PeerSendWorkRequest<'_, 'env>,
15    ) -> TransportResult<ScopedPendingWork<'scope>> {
16        Ok(self.channel_post_send(|n| n.multi_channel.channel(wr.peer), wr.wr)?)
17    }
18
19    /// Posts a receive to the work request's target peer, returning a handle for manual polling.
20    pub fn post_receive(
21        &mut self,
22        wr: PeerReceiveWorkRequest<'_, 'env>,
23    ) -> TransportResult<ScopedPendingWork<'scope>> {
24        Ok(self.channel_post_receive(|n| n.multi_channel.channel(wr.peer), wr.wr)?)
25    }
26
27    /// Posts an RDMA write to the work request's target peer, returning a handle for manual polling.
28    pub fn post_write(
29        &mut self,
30        wr: PeerWriteWorkRequest<'_, 'env>,
31    ) -> TransportResult<ScopedPendingWork<'scope>> {
32        Ok(self.channel_post_write(|n| n.multi_channel.channel(wr.peer), wr.wr)?)
33    }
34
35    /// Posts an RDMA read to the work request's target peer, returning a handle for manual polling.
36    pub fn post_read(
37        &mut self,
38        wr: PeerReadWorkRequest<'_, 'env>,
39    ) -> TransportResult<ScopedPendingWork<'scope>> {
40        Ok(self.channel_post_read(|n| n.multi_channel.channel(wr.peer), wr.wr)?)
41    }
42}
43
44impl Node {
45    /// Posts a send to the work request's target peer and blocks until it completes.
46    pub fn send<'op>(
47        &'op mut self,
48        wr: PeerSendWorkRequest<'op, 'op>,
49    ) -> TransportResult<WorkSuccess> {
50        self.multi_channel.send(wr)
51    }
52
53    /// Posts a receive to the work request's target peer and blocks until it completes.
54    pub fn receive<'op>(
55        &'op mut self,
56        wr: PeerReceiveWorkRequest<'op, 'op>,
57    ) -> TransportResult<WorkSuccess> {
58        self.multi_channel.receive(wr)
59    }
60
61    /// Posts an RDMA write to the work request's target peer and blocks until it completes.
62    pub fn write<'op>(
63        &'op mut self,
64        wr: PeerWriteWorkRequest<'op, 'op>,
65    ) -> TransportResult<WorkSuccess> {
66        self.multi_channel.write(wr)
67    }
68
69    /// Posts an RDMA read to the work request's target peer and blocks until it completes.
70    pub fn read<'op>(
71        &'op mut self,
72        wr: PeerReadWorkRequest<'op, 'op>,
73    ) -> TransportResult<WorkSuccess> {
74        self.multi_channel.read(wr)
75    }
76}
77
78impl Node {
79    /// Posts a send to the target peer without polling for completion.
80    ///
81    /// # Safety
82    /// See [`Channel::send_unpolled`](crate::channel::Channel::send_unpolled).
83    pub unsafe fn send_unpolled<'data>(
84        &mut self,
85        wr: PeerSendWorkRequest<'_, 'data>,
86    ) -> IbvResult<PendingWork<'data>> {
87        unsafe { self.multi_channel.send_unpolled(wr) }
88    }
89
90    /// Posts a receive to the target peer without polling for completion.
91    ///
92    /// # Safety
93    /// See [`Channel::receive_unpolled`](crate::channel::Channel::receive_unpolled).
94    pub unsafe fn receive_unpolled<'data>(
95        &mut self,
96        wr: PeerReceiveWorkRequest<'_, 'data>,
97    ) -> IbvResult<PendingWork<'data>> {
98        unsafe { self.multi_channel.receive_unpolled(wr) }
99    }
100
101    /// Posts an RDMA write to the target peer without polling for completion.
102    ///
103    /// # Safety
104    /// See [`Channel::write_unpolled`](crate::channel::Channel::write_unpolled).
105    pub unsafe fn write_unpolled<'data>(
106        &mut self,
107        wr: PeerWriteWorkRequest<'_, 'data>,
108    ) -> IbvResult<PendingWork<'data>> {
109        unsafe { self.multi_channel.write_unpolled(wr) }
110    }
111
112    /// Posts an RDMA read to the target peer without polling for completion.
113    ///
114    /// # Safety
115    /// See [`Channel::read_unpolled`](crate::channel::Channel::read_unpolled).
116    pub unsafe fn read_unpolled<'data>(
117        &mut self,
118        wr: PeerReadWorkRequest<'_, 'data>,
119    ) -> IbvResult<PendingWork<'data>> {
120        unsafe { self.multi_channel.read_unpolled(wr) }
121    }
122}