]>
git.proxmox.com Git - proxmox-backup.git/blob - pbs-tools/src/io.rs
3 use proxmox_sys
::fd
::Fd
;
5 /// The `BufferedRead` trait provides a single function
6 /// `buffered_read`. It returns a reference to an internal buffer. The
7 /// purpose of this traid is to avoid unnecessary data copies.
8 pub trait BufferedRead
{
9 /// This functions tries to fill the internal buffers, then
10 /// returns a reference to the available data. It returns an empty
11 /// buffer if `offset` points to the end of the file.
12 fn buffered_read(&mut self, offset
: u64) -> Result
<&[u8], anyhow
::Error
>;
15 /// safe wrapper for `nix::unistd::pipe2` defaulting to `O_CLOEXEC` and guarding the file
17 pub fn pipe() -> Result
<(Fd
, Fd
), nix
::Error
> {
18 let (pin
, pout
) = nix
::unistd
::pipe2(nix
::fcntl
::OFlag
::O_CLOEXEC
)?
;
19 Ok((Fd(pin
), Fd(pout
)))