MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / test_splice_offset

Function test_splice_offset

tests/pipe/splice.rs:29–65  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27#[cfg(linux_kernel)]
28#[test]
29fn test_splice_offset() {
30 use rustix::pipe::{pipe, splice, SpliceFlags};
31 use std::io::{Read as _, Write as _};
32
33 let mut src = tempfile::tempfile().unwrap();
34 let mut dest = tempfile::tempfile().unwrap();
35 let (read_p, write_p) = pipe().unwrap();
36 let mut buff = vec![];
37 let mut off_w = 0;
38 let mut off_r = 0;
39
40 writeln!(src, "hello world").unwrap();
41
42 splice(
43 &src,
44 Some(&mut off_w),
45 &write_p,
46 None,
47 5,
48 SpliceFlags::empty(),
49 )
50 .unwrap();
51 splice(
52 &read_p,
53 None,
54 &dest,
55 Some(&mut off_r),
56 5,
57 SpliceFlags::empty(),
58 )
59 .unwrap();
60
61 dest.read_to_end(&mut buff).unwrap();
62 assert_eq!(buff, b"hello");
63 assert_eq!(off_w, 5);
64 assert_eq!(off_r, 5);
65}
66
67#[cfg(feature = "fs")]
68#[cfg(linux_kernel)]

Callers

nothing calls this directly

Calls 2

pipeFunction · 0.50
spliceFunction · 0.50

Tested by

no test coverage detected