TSDuck v3.46-4930
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
Operating system

Portable operating system layer. More...

Collaboration diagram for Operating system:

Topics

 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  tsSysUtils.h

Classes

class  ts::AbortInterface
class  ts::ApplicationSharedLibrary
class  ts::Stdio::BinaryMode
class  ts::Device
class  ts::ForkPipe
class  ts::ForkPipeOutputStream
class  ts::InterruptHandler
class  ts::ISOTime
class  ts::OutputPager
class  ts::Stdio::Redirector
class  ts::ResidentBuffer< T >
class  ts::SharedLibrary
class  ts::Stdio
class  ts::StreamInterface
class  ts::SysInfo
class  ts::SysPipe
class  ts::SystemMonitor
class  ts::Time
class  ts::UserInterrupt
class  ts::Zlib

Typedefs

using ts::ioctl_request_t = platform-dependent
using ts::SysHandleType = platform_specific
using ts::SysProcessIdType = platform_specific

Enumerations

enum class  ts::SharedLibraryFlags : uint16_t {
  ts::SharedLibraryFlags::NONE = 0x00 ,
  ts::SharedLibraryFlags::PERMANENT = 0x01
}

Functions

void ts::AddCloseOnForkExec (int fd, bool cloexec=true)
fs::path ts::CallerLibraryFile ()
fs::path ts::ExecutableFile ()
cn::milliseconds ts::GetProcessCpuTime ()
SysProcessIdType ts::GetProcessId ()
size_t ts::GetProcessVirtualSize ()
void ts::IgnorePipeSignal ()
bool ts::IsPrivilegedUser ()
int ts::LastSysErrorCode ()
bool ts::ProcessIdExists (SysProcessIdType pid)
void ts::RemoveCloseOnForkExec (int fd)
int ts::SetLastSysErrorCode (int error_code)
template<class Rep, class Period>
void ts::SetTimersPrecision (cn::duration< Rep, Period > &precision)
int ts::SysCloseHandle (SysHandleType hfd)
std::string ts::SysErrorCodeMessage (int code=LastSysErrorCode(), const std::error_category *category=nullptr)

Variables

constexpr SysHandleType ts::SYS_HANDLE_INVALID = platform_specific
constexpr SysProcessIdType ts::SYS_PROCESS_ID_INVALID = platform_specific

Detailed Description

Portable operating system layer.

Typedef Documentation

◆ SysHandleType

using ts::SysHandleType = platform_specific

Data type for system file or device handler or descriptor.

See also
SysSocketType

◆ SysProcessIdType

using ts::SysProcessIdType = platform_specific

Data type for system process id.

◆ ioctl_request_t

using ts::ioctl_request_t = platform-dependent

Portable type for ioctl() request parameter.

Enumeration Type Documentation

◆ SharedLibraryFlags

enum class ts::SharedLibraryFlags : uint16_t
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).

Function Documentation

◆ LastSysErrorCode()

int ts::LastSysErrorCode ( )
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.

Returns
The error code of the last operating system call.

◆ SetLastSysErrorCode()

int ts::SetLastSysErrorCode ( int error_code)
inline

Force the error code of the last operating system call.

Parameters
[in]error_codeThe error code to force.
Returns
Value of error_code.

◆ SysErrorCodeMessage()

std::string ts::SysErrorCodeMessage ( int code = LastSysErrorCode(),
const std::error_category * category = nullptr )

Format a system error code into a string.

Parameters
[in]codeAn error code from the operating system. Typically a result from errno (Unix) or GetLastError() (Windows).
[in]categoryError category, system by default.
Returns
A string describing the error.

◆ SysCloseHandle()

int ts::SysCloseHandle ( SysHandleType hfd)
inline

The close() system call which applies to system file or device handler or descriptor.

Parameters
[in]hfdSystem file or device handler or descriptor.
Returns
Error code.

◆ ExecutableFile()

fs::path ts::ExecutableFile ( )

Get the name of the current application executable file.

Returns
The full path of the executable file which is run in the current process.

◆ CallerLibraryFile()

fs::path ts::CallerLibraryFile ( )

Get the name of the executable or shared library file containing the caller code.

Returns
The full path of the file or empty in case of error or if not supported.

◆ IsPrivilegedUser()

bool ts::IsPrivilegedUser ( )

Check if the current user is privileged (root on UNIX, an administrator on Windows).

Returns
True if the current user is privileged.

◆ GetProcessCpuTime()

cn::milliseconds ts::GetProcessCpuTime ( )

Get the CPU time of the process in milliseconds.

Returns
The CPU time of the process in milliseconds.
Exceptions
ts::Exceptionon error.

◆ GetProcessVirtualSize()

size_t ts::GetProcessVirtualSize ( )

Get the virtual memory size of the process in bytes.

Returns
The virtual memory size of the process in bytes.
Exceptions
ts::Exceptionon error.

◆ GetProcessId()

SysProcessIdType ts::GetProcessId ( )

Get the current process id.

Returns
The current process id.

◆ ProcessIdExists()

bool ts::ProcessIdExists ( SysProcessIdType pid)

Check if a process exists.

Parameters
[in]pidProcess id to check.
Returns
True if the process exists, false otherwise.

◆ IgnorePipeSignal()

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).

◆ SetTimersPrecision()

template<class Rep, class Period>
void ts::SetTimersPrecision ( cn::duration< Rep, Period > & precision)

Request a minimum resolution for the system timers.

Parameters
[in,out]precisionOn 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.

◆ AddCloseOnForkExec()

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.

Parameters
[in]fdFile descriptor to close on fork().
[in]cloexecWhen true (the default), the flag FD_CLOEXEC is also set on the file descriptor to enforce a close on exec().
See also
RemoveCloseOnFork()

◆ RemoveCloseOnForkExec()

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.

Parameters
[in]fdFile descriptor to no longer close after fork().
See also
AddCloseOnFork()

Variable Documentation

◆ SYS_HANDLE_INVALID

SysHandleType ts::SYS_HANDLE_INVALID = platform_specific
constexpr

Value of type SysHandleType which is invalid.

◆ SYS_PROCESS_ID_INVALID

SysProcessIdType ts::SYS_PROCESS_ID_INVALID = platform_specific
constexpr

Value of type SysProcessIdType which is invalid.