LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
FdCapture Class Reference

Redirect a file descriptor into a temporary file for a scope, and give back what was written to it. More...

Public Member Functions

 FdCapture (int fd)
 ~FdCapture ()
std::string take ()
 Restore the descriptor and read back what was written.
bool active () const

Detailed Description

Redirect a file descriptor into a temporary file for a scope, and give back what was written to it.

A TEMPORARY FILE AND NOT A PIPE, which was already the choice here and is worth keeping deliberately: a pipe holds 64 KB and nobody is draining it, so a solve that prints more than that would deadlock against its own output.

IT IS AN OBJECT so that the restore happens on the way out of the scope whatever happens inside it. The server's version below did the same dance inline and could not have survived a throw between the dup2 and the restore, which is survivable in a one-shot process and is a leaked file descriptor per call in a host that calls this in a loop.

Definition at line 11796 of file line_cli.cpp.

Constructor & Destructor Documentation

◆ FdCapture()

FdCapture::FdCapture ( int fd)
inlineexplicit

Definition at line 11798 of file line_cli.cpp.

◆ ~FdCapture()

FdCapture::~FdCapture ( )
inline

Definition at line 11818 of file line_cli.cpp.

Member Function Documentation

◆ active()

bool FdCapture::active ( ) const
inline

Definition at line 11838 of file line_cli.cpp.

Referenced by run_invocation_captured().

◆ take()

std::string FdCapture::take ( )
inline

Restore the descriptor and read back what was written.

Idempotent.

Definition at line 11827 of file line_cli.cpp.

Referenced by line::cli::run(), and run_invocation_captured().


The documentation for this class was generated from the following file: