1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//! # High-Level Packet Sending Logic
//!
//! ## Purpose
//!
//! This file provides the high-level `send` methods for the `TxSocket`. It offers a
//! convenient API for users to send packet data without managing the underlying
//! descriptors and rings directly.
//!
//! Since send and send_blocking is not a part of core API,
//! you have to import Send trait to enable it.
//!
//! ## How it works
//!
//! The user must first call `seek` or `seek_n` to ensure one or more UMEM frames
//! are available for writing. The `send` method then takes the user's packet data,
//! copies it into the next available frame, and calls `commit` to submit the
//! descriptor to the kernel for transmission. It also provides a `send_blocking`
//! variant that waits for the send to complete.
//!
//! ## Main components
//!
//! - `impl Socket<_TX>`: An implementation block for the transmit socket.
//! - `send()`: A non-blocking method to send a slice of data.
//! - `send_blocking()`: A blocking method that sends data and waits for the operation
//! to be acknowledged by the kernel.
use cratePollWaitExt;
use crate;
/// A trait for high-level packet sending operations on XDP transmit sockets.
///
/// This trait provides methods to send packet data using an AF_XDP socket. It abstracts
/// away the details of descriptor management and UMEM frame handling, offering a simple
/// interface for non-blocking and blocking sends.
///
/// - `send`: Sends a packet in a non-blocking manner. You must ensure a frame is available
/// by calling `seek` or `seek_n` before use.
/// - `send_blocking`: Sends a packet and blocks until the kernel has processed the send.
///
/// # Arguments
///
/// * `data` - A byte slice containing the packet payload.
/// * `header` - An optional byte slice for the packet header.
///
/// # Errors
///
/// Returns a `RingError` if the send fails or if no frame is available.
///
/// # Example
///
/// ```rust
/// use xdp_socket::{create_tx_socket, SendExt as _ };
/// let mut tx = create_tx_socket(...)?;
/// tx.send(b"hello", None)?;
/// ```
/// An implementation block for the transmit socket (`TxSocket`) that provides
/// high-level sending methods.