dope_core/backend/uring/platform/
gso.rs1use crate::io::socket::msg::MsgHdr;
2use std::ptr;
3
4pub const MAX_GSO_SEGMENTS: usize = 64;
5pub const MAX_GSO_BYTES: usize = 65535;
6
7#[derive(Default)]
8#[repr(C, align(8))]
9pub struct Gso([u8; 32]);
10
11impl Gso {
12 pub const fn new() -> Self {
13 Self([0; 32])
14 }
15
16 pub fn attach(&mut self, msg: &mut MsgHdr, segment_size: u16) {
17 if segment_size == 0 {
18 return;
19 }
20 const DATA_LEN: u32 = size_of::<u16>() as u32;
21 let (buf, cap) = (self.0.as_mut_ptr(), self.0.len());
22 unsafe {
23 let controllen = libc::CMSG_SPACE(DATA_LEN) as usize;
24 debug_assert!(controllen <= cap);
25 msg.set_control(buf.cast(), controllen);
26 let hdr = libc::CMSG_FIRSTHDR(msg.raw());
27 (*hdr).cmsg_level = libc::SOL_UDP;
28 (*hdr).cmsg_type = libc::UDP_SEGMENT;
29 (*hdr).cmsg_len = libc::CMSG_LEN(DATA_LEN) as _;
30 ptr::copy_nonoverlapping(
31 ptr::addr_of!(segment_size).cast::<u8>(),
32 libc::CMSG_DATA(hdr),
33 DATA_LEN as usize,
34 );
35 }
36 }
37}