File descriptor redirection helpers.
More...
#include <fcntl.h>
#include <sys/types.h>
#include <chrono>
#include <cstdint>
#include <ctime>
#include <functional>
#include <span>
#include "../linux.hpp"
Go to the source code of this file.
|
| namespace | ns_linux |
| | Linux-specific system operations.
|
| |
|
| Value< void > | ns_linux::ns_fd::redirect_fd_to_fd (pid_t ppid, int fd_src, int fd_dst) |
| | Redirects the output of one file descriptor as input of another.
|
| |
| Value< void > | ns_linux::ns_fd::redirect_file_to_fd (pid_t ppid, fs::path const &path_file, int fd_dst) |
| | Redirects the output of a file to a file descriptor.
|
| |
| Value< void > | ns_linux::ns_fd::redirect_fd_to_file (pid_t ppid, int fd_src, fs::path const &path_file) |
| | Redirects the output of a file descriptor to a file.
|
| |
| Value< void > | ns_linux::ns_fd::redirect_fd_to_stream (pid_t ppid, int fd_src, std::ostream &stream_dst, std::function< std::string(std::string const &)> transform=[](std::string e) -> std::string { return e;}) |
| | Redirects the output of a file descriptor to a stream.
|
| |
| Value< void > | ns_linux::ns_fd::redirect_stream_to_fd (pid_t ppid, std::istream &stream_src, int fd_dst) |
| | Redirects the output of a stream to a file descriptor.
|
| |
File descriptor redirection helpers.
- Author
- Ruan Formigoni
- Copyright
- Copyright (c) 2025 Ruan Formigoni
Definition in file fd.hpp.
◆ redirect_fd_to_fd()
| Value< void > ns_linux::ns_fd::redirect_fd_to_fd |
( |
pid_t | ppid, |
|
|
int | fd_src, |
|
|
int | fd_dst ) |
|
inlinenodiscard |
Redirects the output of one file descriptor as input of another.
- Parameters
-
| ppid | Keep trying to read and write while this pid is alive |
| fd_src | File descriptor to read from |
| fd_dst | File descriptor to write to |
Definition at line 35 of file fd.hpp.
◆ redirect_fd_to_file()
| Value< void > ns_linux::ns_fd::redirect_fd_to_file |
( |
pid_t | ppid, |
|
|
int | fd_src, |
|
|
fs::path const & | path_file ) |
|
inlinenodiscard |
Redirects the output of a file descriptor to a file.
- Parameters
-
| ppid | Keep trying to read and write while this pid is alive |
| fd_src | Path to the file descriptor to read from |
| path_file_file | Path to the file to write to |
- Returns
- std::jthread Returns the spawned redirector thread
Definition at line 120 of file fd.hpp.
◆ redirect_fd_to_stream()
| Value< void > ns_linux::ns_fd::redirect_fd_to_stream |
( |
pid_t | ppid, |
|
|
int | fd_src, |
|
|
std::ostream & | stream_dst, |
|
|
std::function< std::string(std::string const &)> | transform = [](std::string e) -> std::string { return e; } ) |
|
inlinenodiscard |
Redirects the output of a file descriptor to a stream.
Reads data from a file descriptor and writes it to an output stream. Continues reading while the specified process is alive.
- Parameters
-
| ppid | Keep trying to read and write while this pid is alive |
| fd_src | File descriptor to read from |
| stream_dst | Output stream to write to |
| transform | Optionally transforms the read data before writing to the stream |
Definition at line 151 of file fd.hpp.
◆ redirect_file_to_fd()
| Value< void > ns_linux::ns_fd::redirect_file_to_fd |
( |
pid_t | ppid, |
|
|
fs::path const & | path_file, |
|
|
int | fd_dst ) |
|
inlinenodiscard |
Redirects the output of a file to a file descriptor.
- Parameters
-
| ppid | Keep trying to read and write while this pid is alive |
| path_file_file | Path to the file to read from |
| fd_dst | Path to the file descriptor to write to |
- Returns
- std::jthread Returns the spawned redirector thread
Definition at line 93 of file fd.hpp.
◆ redirect_stream_to_fd()
| Value< void > ns_linux::ns_fd::redirect_stream_to_fd |
( |
pid_t | ppid, |
|
|
std::istream & | stream_src, |
|
|
int | fd_dst ) |
|
inlinenodiscard |
Redirects the output of a stream to a file descriptor.
Reads lines from an input stream and writes them to a file descriptor. Continues reading while the specified process is alive.
- Parameters
-
| ppid | Keep trying to read and write while this pid is alive |
| stream_src | Input stream to read from |
| fd_dst | File descriptor to write to |
Definition at line 205 of file fd.hpp.
◆ SECONDS_TIMEOUT
| uint32_t const ns_linux::ns_fd::SECONDS_TIMEOUT = 5 |
|
constexpr |
◆ SIZE_BUFFER_READ
| uint32_t const ns_linux::ns_fd::SIZE_BUFFER_READ = 16384 |
|
constexpr |
◆ TIMEOUT_RETRY
| auto const ns_linux::ns_fd::TIMEOUT_RETRY = std::chrono::milliseconds(50) |
|
constexpr |