3 use crate::fd
::OwnedFd
;
4 use crate::{backend, io}
;
5 #[cfg(any(target_os = "android", target_os = "linux"))]
8 #[cfg(not(any(target_os = "ios", target_os = "macos")))]
9 pub use backend
::io
::types
::PipeFlags
;
11 #[cfg(any(target_os = "android", target_os = "linux"))]
12 pub use backend
::io
::types
::{IoSliceRaw, SpliceFlags}
;
14 /// `PIPE_BUF`—The maximum length at which writes to a pipe are atomic.
20 /// [Linux]: https://man7.org/linux/man-pages/man7/pipe.7.html
21 /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html
25 target_os
= "illumos",
27 target_os
= "solaris",
30 pub const PIPE_BUF
: usize = backend
::io
::types
::PIPE_BUF
;
32 /// `pipe()`—Creates a pipe.
34 /// This function creates a pipe and returns two file descriptors, for the
35 /// reading and writing ends of the pipe, respectively.
41 /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/pipe.html
42 /// [Linux]: https://man7.org/linux/man-pages/man2/pipe.2.html
44 pub fn pipe() -> io
::Result
<(OwnedFd
, OwnedFd
)> {
45 backend
::io
::syscalls
::pipe()
48 /// `pipe2(flags)`—Creates a pipe, with flags.
50 /// This function creates a pipe and returns two file descriptors, for the
51 /// reading and writing ends of the pipe, respectively.
56 /// [Linux]: https://man7.org/linux/man-pages/man2/pipe2.2.html
64 #[doc(alias = "pipe2")]
65 pub fn pipe_with(flags
: PipeFlags
) -> io
::Result
<(OwnedFd
, OwnedFd
)> {
66 backend
::io
::syscalls
::pipe_with(flags
)
69 /// `splice(fd_in, off_in, fd_out, off_out, len, flags)`—Transfer data between a file and a pipe.
71 /// This function transfers up to `len` bytes of data from the file descriptor `fd_in`
72 /// to the file descriptor `fd_out`, where one of the file descriptors
73 /// must refer to a pipe.
75 /// `off_*` must be `None` if the corresponding fd refers to a pipe.
76 /// Otherwise its value points to the starting offset to the file,
77 /// from which the data is read/written.
78 /// on success the number of bytes read/written is added to the offset.
80 /// passing `None` causes the read/write to start from the file offset,
81 /// and the file offset is adjusted appropriately.
86 /// [Linux]: https://man7.org/linux/man-pages/man2/splice.2.html
87 #[cfg(any(target_os = "android", target_os = "linux"))]
89 pub fn splice
<FdIn
: AsFd
, FdOut
: AsFd
>(
91 off_in
: Option
<&mut u64>,
93 off_out
: Option
<&mut u64>,
96 ) -> io
::Result
<usize> {
97 backend
::io
::syscalls
::splice(fd_in
.as_fd(), off_in
, fd_out
.as_fd(), off_out
, len
, flags
)
100 /// `vmsplice(fd, bufs, flags)`—Transfer data between memory and a pipe.
102 /// If `fd` is the write end of the pipe,
103 /// the function maps the memory pointer at by `bufs` to the pipe.
105 /// If `fd` is the read end of the pipe,
106 /// the function writes data from the pipe to said memory.
110 /// If the memory must not be mutated (such as when `bufs` were originally immutable slices),
111 /// it is up to the caller to ensure that the write end of the pipe is placed in `fd`.
113 /// Additionally if `SpliceFlags::GIFT` is set, the caller must also ensure
114 /// that the contents of `bufs` in never modified following the call,
115 /// and that all of the pointers in `bufs` are page aligned,
116 /// and the lengths are multiples of a page size in bytes.
121 /// [Linux]: https://man7.org/linux/man-pages/man2/vmsplice.2.html
122 #[cfg(any(target_os = "android", target_os = "linux"))]
124 pub unsafe fn vmsplice
<PipeFd
: AsFd
>(
126 bufs
: &[io
::IoSliceRaw
],
128 ) -> io
::Result
<usize> {
129 backend
::io
::syscalls
::vmsplice(fd
.as_fd(), bufs
, flags
)