FlatImage
A configurable Linux containerization system
Loading...
Searching...
No Matches
fd.hpp File Reference

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"
Include dependency graph for fd.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  ns_linux
 Linux-specific system operations.
 

Functions

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.
 

Variables

constexpr uint32_t const ns_linux::ns_fd::SECONDS_TIMEOUT = 5
 
constexpr uint32_t const ns_linux::ns_fd::SIZE_BUFFER_READ = 16384
 
constexpr auto const ns_linux::ns_fd::TIMEOUT_RETRY = std::chrono::milliseconds(50)
 

Detailed Description

File descriptor redirection helpers.

Author
Ruan Formigoni

Definition in file fd.hpp.

Function Documentation

◆ 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
ppidKeep trying to read and write while this pid is alive
fd_srcFile descriptor to read from
fd_dstFile descriptor to write to

Definition at line 35 of file fd.hpp.

Here is the call graph for this function:

◆ 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
ppidKeep trying to read and write while this pid is alive
fd_srcPath to the file descriptor to read from
path_file_filePath to the file to write to
Returns
std::jthread Returns the spawned redirector thread

Definition at line 120 of file fd.hpp.

Here is the call graph for this function:

◆ 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
ppidKeep trying to read and write while this pid is alive
fd_srcFile descriptor to read from
stream_dstOutput stream to write to
transformOptionally 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
ppidKeep trying to read and write while this pid is alive
path_file_filePath to the file to read from
fd_dstPath to the file descriptor to write to
Returns
std::jthread Returns the spawned redirector thread

Definition at line 93 of file fd.hpp.

Here is the call graph for this function:

◆ 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
ppidKeep trying to read and write while this pid is alive
stream_srcInput stream to read from
fd_dstFile descriptor to write to

Definition at line 205 of file fd.hpp.

Here is the call graph for this function:

Variable Documentation

◆ SECONDS_TIMEOUT

uint32_t const ns_linux::ns_fd::SECONDS_TIMEOUT = 5
constexpr

Definition at line 24 of file fd.hpp.

◆ SIZE_BUFFER_READ

uint32_t const ns_linux::ns_fd::SIZE_BUFFER_READ = 16384
constexpr

Definition at line 25 of file fd.hpp.

◆ TIMEOUT_RETRY

auto const ns_linux::ns_fd::TIMEOUT_RETRY = std::chrono::milliseconds(50)
constexpr

Definition at line 26 of file fd.hpp.