![]() |
TSDuck v3.44-4659
MPEG Transport Stream Toolkit
|
Portable operating system layer. More...

Modules | |
| File system | |
| File system and file path features (in addition to std::filesystem). | |
| Environment variables | |
| System environment variables features. | |
| Multi-threading | |
| Multi-threading and synchronization features. | |
| Unix | |
| Unix specific features. | |
| Windows | |
| Windows specific features. | |
Files | |
| file | tsFileUtils.h |
| File utilities (file path, file properties, etc). | |
| file | tsSysUtils.h |
| Various system utilities. | |
Classes | |
| class | ts::AbortInterface |
| An interface to check for abort. More... | |
| class | ts::AbstractReadStreamInterface |
| Abstract interface to read raw data from a stream. More... | |
| class | ts::AbstractWriteStreamInterface |
| Abstract interface to write raw data on a stream. More... | |
| class | ts::ApplicationSharedLibrary |
| Representation of an application shared library. More... | |
| class | ts::ForkPipe |
| Fork a process and create an optional pipe to its standard input. More... | |
| class | ts::InputRedirector |
| A class to redirect an input stream. More... | |
| class | ts::InterruptHandler |
| An interface to be implemented by a class to handle user Ctrl-C interrupt. More... | |
| class | ts::ISOTime |
The ISOTime class convert dates, times, and durations with ISO 8601 representation. More... | |
| class | ts::NonBlockingDevice |
| Base class for devices, files, or sockets which can work in non-blocking mode. More... | |
| class | ts::OutputPager |
| Send application output to a "pager" application such as "more" or "less". More... | |
| class | ts::OutputRedirector |
| A class to redirect an output stream. More... | |
| class | ts::ResidentBuffer< T > |
| Implementation of memory buffer locked in physical memory. More... | |
| class | ts::SharedLibrary |
| Shared library handling (.so on Linux, .dylib on macOS, .dll on Windows). More... | |
| class | ts::SysInfo |
| A singleton holding information on the current operating system. More... | |
| class | ts::SystemMonitor |
| Monitoring thread for system resources used by the application. More... | |
| class | ts::Time |
The Time class implements a basic representation of time. More... | |
| class | ts::UserInterrupt |
| An instance of this class handles the Ctrl+C user interrupt. More... | |
| class | ts::Zlib |
| Implementation of RFC 1951 data compression, a.k.a. More... | |
Typedefs | |
| using | ts::ioctl_request_t = platform-dependent |
| Portable type for ioctl() request parameter. | |
Enumerations | |
| enum class | ts::SharedLibraryFlags : uint16_t { ts::SharedLibraryFlags::NONE = 0x00 , ts::SharedLibraryFlags::PERMANENT = 0x01 } |
| Bit masks options to load shared libraries. More... | |
Functions | |
| void | ts::AddCloseOnForkExec (int fd, bool cloexec=true) |
Close a file descriptor on fork(). | |
| fs::path | ts::CallerLibraryFile () |
| Get the name of the executable or shared library file containing the caller code. | |
| fs::path | ts::ExecutableFile () |
| Get the name of the current application executable file. | |
| cn::milliseconds | ts::GetProcessCpuTime () |
| Get the CPU time of the process in milliseconds. | |
| size_t | ts::GetProcessVirtualSize () |
| Get the virtual memory size of the process in bytes. | |
| void | ts::IgnorePipeSignal () |
| Ensure that writing to a broken pipe does not kill the current process. | |
| bool | ts::IsPrivilegedUser () |
| Check if the current user is privileged (root on UNIX, an administrator on Windows). | |
| int | ts::LastSysErrorCode () |
| Get the error code of the last operating system call. | |
| void | ts::RemoveCloseOnForkExec (int fd) |
Remove a file descriptor from the list of those to close on fork(). | |
| bool | ts::SetBinaryModeStdin (Report &report=(ts::CerrReport::Instance())) |
| Put the standard input stream in binary mode. | |
| bool | ts::SetBinaryModeStdout (Report &report=(ts::CerrReport::Instance())) |
| Put the standard output stream in binary mode. | |
| template<class Rep , class Period > | |
| void | ts::SetTimersPrecision (cn::duration< Rep, Period > &precision) |
| Request a minimum resolution for the system timers. | |
| bool | ts::StdErrIsTerminal () |
| Check if the standard error is a terminal. | |
| bool | ts::StdInIsTerminal () |
| Check if the standard input is a terminal. | |
| bool | ts::StdOutIsTerminal () |
| Check if the standard output is a terminal. | |
| std::string | ts::SysErrorCodeMessage (int code=LastSysErrorCode(), const std::error_category &category=std::system_category()) |
| Format a system error code into a string. | |
Portable operating system layer.
|
strong |
Bit masks options to load shared libraries.
| Enumerator | |
|---|---|
| NONE | No option. |
| PERMANENT | The shared library remains active when the SharedLibrary object is destroyed (unloaded otherwise). |
|
inline |
Get the error code of the last operating system call.
The validity of the returned value may depends on specific conditions.
Portability of error code representation: On UNIX, error codes are just int. On Windows, error codes are DWORD, which is compatible with int. In C++11, std::error_core uses int for error codes. Therefore, because of this new C++11 feature, we just use int.
Windows note: According to Windows documentation, socket functions should call WSAGetLastError() instead of GetLastError() to retrieve the error code. This is an oddity from the old 16-bit Windows API. On Win32, various sources confirm that WSAGetLastError() just call GetLastError(). Thus, in this application, we do not make the difference.
|
inline |
Format a system error code into a string.
| [in] | code | An error code from the operating system. Typically a result from errno (Unix) or GetLastError() (Windows). |
| [in] | category | Error category, system by default. |
| fs::path ts::ExecutableFile | ( | ) |
Get the name of the current application executable file.
| fs::path ts::CallerLibraryFile | ( | ) |
Get the name of the executable or shared library file containing the caller code.
| bool ts::IsPrivilegedUser | ( | ) |
Check if the current user is privileged (root on UNIX, an administrator on Windows).
| cn::milliseconds ts::GetProcessCpuTime | ( | ) |
Get the CPU time of the process in milliseconds.
| ts::Exception | on error. |
| size_t ts::GetProcessVirtualSize | ( | ) |
Get the virtual memory size of the process in bytes.
| ts::Exception | on error. |
| void ts::IgnorePipeSignal | ( | ) |
Ensure that writing to a broken pipe does not kill the current process.
On UNIX systems, writing to a broken pipe, i.e. a pipe with no process reading from it, kills the current process. This may not be what you want. This functions prevents this.
UNIX Systems: This function ignores SIGPIPE. Writing to a broken pipe will now return an error instead of killing the process.
Windows systems: This function does nothing (because there is no need to do anything).
| void ts::SetTimersPrecision | ( | cn::duration< Rep, Period > & | precision | ) |
Request a minimum resolution for the system timers.
| [in,out] | precision | On input, specify the requested minimum resolution in any std::chrono::duration units. On output, return the obtained guaranteed minimum resolution. The guaranteed precision value can be equal to or greater than the requested value. The default system resolution is 20 ms on Win32, which can be too long for applications. |
| bool ts::StdInIsTerminal | ( | ) |
Check if the standard input is a terminal.
| bool ts::StdOutIsTerminal | ( | ) |
Check if the standard output is a terminal.
| bool ts::StdErrIsTerminal | ( | ) |
Check if the standard error is a terminal.
| bool ts::SetBinaryModeStdin | ( | Report & | report = (ts::CerrReport::Instance()) | ) |
Put the standard input stream in binary mode.
On UNIX systems, this does not make any difference. On Windows systems, however, in a stream which is not open in binary mode, there is automatic translation between LF and CR-LF. The standard input is open in text mode (non-binary). This function forces it into binary mode.
| [in,out] | report | Where to report errors. |
| bool ts::SetBinaryModeStdout | ( | Report & | report = (ts::CerrReport::Instance()) | ) |
Put the standard output stream in binary mode.
On UNIX systems, this does not make any difference. On Windows systems, however, in a stream which is not open in binary mode, there is automatic translation between LF and CR-LF. The standard output is open in text mode (non-binary). This function forces it into binary mode.
| [in,out] | report | Where to report errors. |
| void ts::AddCloseOnForkExec | ( | int | fd, |
| bool | cloexec = true |
||
| ) |
Close a file descriptor on fork().
On UNIX systems, open file descriptors are inherited on fork() and exec(). Most of the time (but not always), a file descriptor has no meaning outside the process which created it and it is better to close it after fork() (in the child process) and after exec() (in the new program). It is possible to automatically close a file descriptor after exec() using the FD_CLOEXEC and O_CLOEXEC flags. However, there is no equivalent flog to close the file descriptor in a child process after fork(). This function is a solution to that problem.
The provided file descriptor is stored in a global list. After fork(), in the child process, all file descriptors from that list are closed.
Warning 1: There is still a possible race condition if a child process is created between the creation of the file descriptor and the call to AddCloseOnFork().
Warning 2: Do not forget to call RemoveCloseOnFork() just before closing the file descriptor. If you fail to do so, the file descriptor may be reallocated to a new device and it would be unintentionally closed on fork(). Be sure to call RemoveCloseOnFork() before closing the file descriptor, not after. If called after, there is a possible race condition if the file descriptor is immediately reallocated by the system.
This function is specific to UNIX systems and does nothing on Windows.
| [in] | fd | File descriptor to close on fork(). |
| [in] | cloexec | When true (the default), the flag FD_CLOEXEC is also set on the file descriptor to enforce a close on exec(). |
| void ts::RemoveCloseOnForkExec | ( | int | fd | ) |
Remove a file descriptor from the list of those to close on fork().
This function is specific to UNIX systems and does nothing on Windows.
| [in] | fd | File descriptor to no longer close after fork(). |