![]() |
TSDuck v3.45-4766
MPEG Transport Stream Toolkit
|
Encapsulate a system pipe, UNIX or Windows. More...
#include <tsSysPipe.h>


Public Types | |
| enum | Flags { NONE = 0x0000 , READ_ASYNC = 0x0001 , WRITE_ASYNC = 0x0002 , READ_CLOEXEC = 0x0004 , WRITE_CLOEXEC = 0x0008 , READ_INHERIT = 0x0010 , WRITE_INHERIT = 0x0020 } |
| Pipe creation flags. More... | |
Public Member Functions | |
| SysPipe (Report *report) | |
| Constructor. | |
| SysPipe (ReporterBase *delegate) | |
| Constructor. | |
| virtual | ~SysPipe () override |
| Virtual destructor. | |
| bool | close (bool silent=false) |
| Close the pipe file descriptors which are not "fetched". | |
| bool | create (Flags flags=NONE, size_t buffer_size=0) |
| Create the pipe and open the two file descriptors. | |
| SysHandleType | fetchRead () |
| "Fetch" the read file descriptor of the pipe. | |
| SysHandleType | fetchWrite () |
| "Fetch" the write file descriptor of the pipe. | |
| bool | muteReport (bool mute) |
| Temporarily mute the associated report. | |
| SysHandleType | peekRead () |
| "Peek" the read file descriptor of the pipe. | |
| SysHandleType | peekWrite () |
| "Peek" the write file descriptor of the pipe. | |
| virtual Report & | report () const override |
| Access the Report which is associated with this object. | |
| Report * | setReport (Report *report) |
| Associate this object with another Report to log errors. | |
| ReporterBase * | setReport (ReporterBase *delegate) |
| Associate this object with another ReporterBase to log errors. | |
Static Public Member Functions | |
| static int | SilentLevel (bool silent, int default_severity=Severity::Error) |
| Compute a log severity level from a "silent" parameter. | |
Encapsulate a system pipe, UNIX or Windows.
A pipe has two file descriptors / system handles, one for the write end, one for the read end. This class is useful to create pipes, fetch "useful" file descriptors (e.g. to pass to a child process), and let the unused file descriptors be closed in the destructor. This is a safe way to never forget to close unused file descriptors, regardless of error patch.
Once open, the file descriptors / system handles can be either "fetched" or "peeked".
On Windows, asynchronous I/O are not supported in anonymous pipes (as created by CreatePipe).
| enum ts::SysPipe::Flags |
Pipe creation flags.
|
inlineexplicit |
Constructor.
| [in] | report | Where to report errors. The report object must remain valid as long as this object exists or setReport() is used with another Report object. If report is null, log messages are discarded. |
|
inlineexplicit |
Constructor.
| [in] | delegate | Use the report of another ReporterBase. If delegate is null, log messages are discarded. |
|
overridevirtual |
Virtual destructor.
The file descriptor which were not "fetched" are closed.
Create the pipe and open the two file descriptors.
| [in] | flags | Creation flags. |
| [in] | buffer_size | The pipe buffer size in bytes, on Windows. Zero means default. Ignored on UNIX. |
| bool ts::SysPipe::close | ( | bool | silent = false | ) |
Close the pipe file descriptors which are not "fetched".
| [in] | silent | If true, do not report errors. |
|
inline |
"Peek" the read file descriptor of the pipe.
The file descriptor remains in this object and will be closed when this object is closed.
|
inline |
"Peek" the write file descriptor of the pipe.
The file descriptor remains in this object and will be closed when this object is closed.
| SysHandleType ts::SysPipe::fetchRead | ( | ) |
"Fetch" the read file descriptor of the pipe.
The file descriptor is then removed from this object and will not be closed when this object is closed. This is typically used when we need the file descriptor to keep it open for later usage. When there is no read file descriptor in this object, an error is reported.
| SysHandleType ts::SysPipe::fetchWrite | ( | ) |
"Fetch" the write file descriptor of the pipe.
The file descriptor is then removed from this object and will not be closed when this object is closed. This is typically used when we need the file descriptor to keep it open for later usage. When there is no write file descriptor in this object, an error is reported.
|
overridevirtualinherited |
Access the Report which is associated with this object.
Can be called from another thread only if the Report object is thread-safe.
Implements ts::ReporterInterface.
Associate this object with another Report to log errors.
| [in] | report | Where to report errors. The report object must remain valid as long as this object exists or setReport() is used with another Report object. If report is null, log messages are discarded. |
|
inherited |
Associate this object with another ReporterBase to log errors.
| [in] | delegate | Use the report of another ReporterBase. If delegate is null, the previous explicit Report is used.. |
|
inherited |
Temporarily mute the associated report.
| [in] | mute | It true, report() will return a null report (log messages are discarded), until muteReport() is invoked again with mute set to false. |
|
inlinestaticinherited |
Compute a log severity level from a "silent" parameter.
Some subclass methods have a "silent" parameter to avoid reporting errors which may be insignificant, typically when closing a device after an error, in which case the close operation may produce other errors if the previous error left the device in an inconsistent state. While those errors should not be displayed as errors, we still display them at debug level.
| [in] | silent | If true, do not report errors, report debug messages instead. |
| [in] | default_severity | Default severity, in non-silent mode (error by default). |