forked from compio-rs/compio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathancillary.rs
More file actions
46 lines (39 loc) · 1.24 KB
/
ancillary.rs
File metadata and controls
46 lines (39 loc) · 1.24 KB
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
use std::mem::MaybeUninit;
use compio_buf::IoBuf;
use compio_io::ancillary::{AncillaryBuf, AncillaryIter, CMsgBuilder};
#[test]
fn test_cmsg() {
let mut buf = AncillaryBuf::<64>::new();
let mut builder = buf.builder();
builder.try_push(0, 0, ()).unwrap(); // 16 / 12
builder.try_push(1, 1, u32::MAX).unwrap(); // 16 + 4 + 4 / 12 + 4
builder.try_push(2, 2, i64::MIN).unwrap(); // 16 + 8 / 12 + 8
assert!(buf.buf_len() == 64 || buf.buf_len() == 48);
unsafe {
let mut iter = AncillaryIter::new(&buf);
let cmsg = iter.next().unwrap();
assert_eq!((cmsg.level(), cmsg.ty(), cmsg.data::<()>()), (0, 0, &()));
let cmsg = iter.next().unwrap();
assert_eq!(
(cmsg.level(), cmsg.ty(), cmsg.data::<u32>()),
(1, 1, &u32::MAX)
);
let cmsg = iter.next().unwrap();
assert_eq!(
(cmsg.level(), cmsg.ty(), cmsg.data::<i64>()),
(2, 2, &i64::MIN)
);
assert!(iter.next().is_none());
}
}
#[test]
#[should_panic]
fn invalid_buffer_length() {
AncillaryBuf::<1>::new().builder();
}
#[test]
#[should_panic]
fn invalid_buffer_alignment() {
let mut buf = [MaybeUninit::new(0u8); 64];
CMsgBuilder::new(&mut buf[1..]);
}