ibverbs_rs/channel/ops/unpolled_ops.rs
1use crate::channel::Channel;
2use crate::channel::pending_work::PendingWork;
3use crate::ibverbs::error::IbvResult;
4use crate::ibverbs::work::{
5 ReadWorkRequest, ReceiveWorkRequest, SendWorkRequest, WriteWorkRequest,
6};
7
8impl Channel {
9 /// Posts a send operation without polling for completion.
10 ///
11 /// # Safety
12 /// The returned [`PendingWork`] must not be leaked (e.g. via [`mem::forget`](std::mem::forget)),
13 /// as this would end the borrow without dropping while the hardware may still access the memory.
14 /// Prefer [`scope`](Channel::scope) or [`manual_scope`](Channel::manual_scope) which prevent this.
15 pub unsafe fn send_unpolled<'data>(
16 &mut self,
17 wr: SendWorkRequest<'_, 'data>,
18 ) -> IbvResult<PendingWork<'data>> {
19 let wr_id = self.get_and_advance_wr_id();
20 unsafe { self.qp.post_send(wr, wr_id)? };
21 Ok(unsafe { PendingWork::new(wr_id, self.cq.clone()) })
22 }
23
24 /// Posts a receive operation without polling for completion.
25 ///
26 /// # Safety
27 /// The returned [`PendingWork`] must not be leaked (e.g. via [`mem::forget`](std::mem::forget)),
28 /// as this would end the borrow without dropping while the hardware may still access the memory.
29 /// Prefer [`scope`](Channel::scope) or [`manual_scope`](Channel::manual_scope) which prevent this.
30 pub unsafe fn receive_unpolled<'data>(
31 &mut self,
32 wr: ReceiveWorkRequest<'_, 'data>,
33 ) -> IbvResult<PendingWork<'data>> {
34 let wr_id = self.get_and_advance_wr_id();
35 unsafe { self.qp.post_receive(wr, wr_id)? };
36 Ok(unsafe { PendingWork::new(wr_id, self.cq.clone()) })
37 }
38
39 /// Posts an RDMA write operation without polling for completion.
40 ///
41 /// # Safety
42 /// The returned [`PendingWork`] must not be leaked (e.g. via [`mem::forget`](std::mem::forget)),
43 /// as this would end the borrow without dropping while the hardware may still access the memory.
44 /// Prefer [`scope`](Channel::scope) or [`manual_scope`](Channel::manual_scope) which prevent this.
45 pub unsafe fn write_unpolled<'data>(
46 &mut self,
47 wr: WriteWorkRequest<'_, 'data>,
48 ) -> IbvResult<PendingWork<'data>> {
49 let wr_id = self.get_and_advance_wr_id();
50 unsafe { self.qp.post_write(wr, wr_id)? };
51 Ok(unsafe { PendingWork::new(wr_id, self.cq.clone()) })
52 }
53
54 /// Posts an RDMA read operation without polling for completion.
55 ///
56 /// # Safety
57 /// The returned [`PendingWork`] must not be leaked (e.g. via [`mem::forget`](std::mem::forget)),
58 /// as this would end the borrow without dropping while the hardware may still access the memory.
59 /// Prefer [`scope`](Channel::scope) or [`manual_scope`](Channel::manual_scope) which prevent this.
60 pub unsafe fn read_unpolled<'data>(
61 &mut self,
62 wr: ReadWorkRequest<'_, 'data>,
63 ) -> IbvResult<PendingWork<'data>> {
64 let wr_id = self.get_and_advance_wr_id();
65 unsafe { self.qp.post_read(wr, wr_id)? };
66 Ok(unsafe { PendingWork::new(wr_id, self.cq.clone()) })
67 }
68
69 fn get_and_advance_wr_id(&mut self) -> u64 {
70 let wr_id = self.next_wr_id;
71 self.next_wr_id += 1;
72 wr_id
73 }
74}