blob: 7db65b9aa54d6b8bf163b03ffe22c976753075eb (
plain)
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
|
use std::io::prelude::*;
use std::os::unix::prelude::*;
use tempfile::tempfile;
use libc::off_t;
use nix::unistd::{close, pipe, read};
use nix::sys::sendfile::sendfile;
#[test]
fn test_sendfile() {
const CONTENTS: &'static [u8] = b"abcdef123456";
let mut tmp = tempfile().unwrap();
tmp.write(CONTENTS).unwrap();
let (rd, wr) = pipe().unwrap();
let mut offset: off_t = 5;
let res = sendfile(wr, tmp.as_raw_fd(), Some(&mut offset), 2).unwrap();
assert_eq!(2, res);
let mut buf = [0u8; 1024];
assert_eq!(2, read(rd, &mut buf).unwrap());
assert_eq!(b"f1", &buf[0..2]);
assert_eq!(7, offset);
close(rd).unwrap();
close(wr).unwrap();
}
|