Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qcore_unix_p.h File Reference

(f96a17225f088a5790655c01eaab9578c81a19f2)

#include "qplatformdefs.h"
#include <QtCore/private/qglobal_p.h>
#include "qbytearray.h"
#include "qdeadlinetimer.h"
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/select.h>
#include <sys/time.h>
#include <chrono>
#include <sys/wait.h>
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
+ Include dependency graph for qcore_unix_p.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

union  qt_semun
 

Macros

#define QT_EINTR_LOOP(var, cmd)
 
#define QT_OPEN   qt_safe_open
 
#define QT_READ   qt_safe_read
 
#define QT_WRITE   qt_safe_write
 
#define QT_CLOSE   qt_safe_close
 
#define _POSIX_MONOTONIC_CLOCK   -1
 

Functions

QT_BEGIN_NAMESPACE Q_DECLARE_TYPEINFO (pollfd, Q_PRIMITIVE_TYPE)
 
timespec durationToTimespec (std::chrono::nanoseconds timeout) noexcept
 
template<typename Duration >
Duration timespecToChrono (timespec ts) noexcept
 
std::chrono::milliseconds timespecToChronoMs (timespec ts) noexcept
 
constexpr timespec & normalizedTimespec (timespec &t)
 
constexpr bool operator< (const timespec &t1, const timespec &t2)
 
constexpr bool operator== (const timespec &t1, const timespec &t2)
 
constexpr bool operator!= (const timespec &t1, const timespec &t2)
 
constexpr timespec & operator+= (timespec &t1, const timespec &t2)
 
constexpr timespec operator+ (const timespec &t1, const timespec &t2)
 
constexpr timespec operator- (const timespec &t1, const timespec &t2)
 
constexpr timespec operator* (const timespec &t1, int mul)
 
timeval timespecToTimeval (timespec ts)
 
timespec & operator+= (timespec &t1, std::chrono::milliseconds msecs)
 
timespec & operator+= (timespec &t1, int ms)
 
timespec operator+ (const timespec &t1, std::chrono::milliseconds msecs)
 
timespec operator+ (const timespec &t1, int ms)
 
timespec qAbsTimespec (timespec ts)
 
Q_CORE_EXPORT void qt_ignore_sigpipe () noexcept
 
static int qt_safe_open (const char *pathname, int flags, mode_t mode=0777)
 
static int qt_safe_pipe (int pipefd[2], int flags=0)
 
static int qt_safe_dup (int oldfd, int atleast=0, int flags=FD_CLOEXEC)
 
static int qt_safe_dup2 (int oldfd, int newfd, int flags=FD_CLOEXEC)
 
static qint64 qt_safe_read (int fd, void *data, qint64 maxlen)
 
static qint64 qt_safe_write (int fd, const void *data, qint64 len)
 
static qint64 qt_safe_write_nosignal (int fd, const void *data, qint64 len)
 
static int qt_safe_close (int fd)
 
QByteArray qt_readlink (const char *path)
 
bool qt_haveLinuxProcfs ()
 
Q_CORE_EXPORT int qt_safe_poll (struct pollfd *fds, nfds_t nfds, QDeadlineTimer deadline)
 
static struct pollfd qt_make_pollfd (int fd, short events)
 

Variables

static constexpr auto OneSecAsNsecs = std::chrono::nanoseconds(std::chrono::seconds{ 1 }).count()
 

Macro Definition Documentation

◆ _POSIX_MONOTONIC_CLOCK

#define _POSIX_MONOTONIC_CLOCK   -1

Definition at line 362 of file qcore_unix_p.h.

◆ QT_CLOSE

◆ QT_EINTR_LOOP

◆ QT_OPEN

◆ QT_READ

◆ QT_WRITE

#define QT_WRITE   qt_safe_write

Definition at line 312 of file qcore_unix_p.h.

Referenced by qt_safe_write(), and QFSFileEnginePrivate::writeFdFh().

Function Documentation

◆ durationToTimespec()

timespec durationToTimespec ( std::chrono::nanoseconds timeout)
inlinenoexcept

Definition at line 70 of file qcore_unix_p.h.

Referenced by QtLinuxFutex::futexWait(), QtFreeBSDFutex::futexWait(), operator+=(), qt_abstime_for_timeout(), qt_safe_poll(), QFileSystemEngine::setFileTime(), QThread::sleep(), and QMutexPrivate::wait().

+ Here is the caller graph for this function:

◆ normalizedTimespec()

constexpr timespec & normalizedTimespec ( timespec & t)
inlineconstexpr

Definition at line 94 of file qcore_unix_p.h.

References OneSecAsNsecs.

Referenced by operator*(), operator+(), operator+=(), operator-(), and qAbsTimespec().

+ Here is the caller graph for this function:

◆ operator!=()

constexpr bool operator!= ( const timespec & t1,
const timespec & t2 )
inlineconstexpr

Definition at line 110 of file qcore_unix_p.h.

References t2.

Referenced by QT6_ONLY().

+ Here is the caller graph for this function:

◆ operator*()

constexpr timespec operator* ( const timespec & t1,
int mul )
inlineconstexpr

Definition at line 132 of file qcore_unix_p.h.

References normalizedTimespec().

+ Here is the call graph for this function:

◆ operator+() [1/3]

constexpr timespec operator+ ( const timespec & t1,
const timespec & t2 )
inlineconstexpr

Definition at line 118 of file qcore_unix_p.h.

References normalizedTimespec(), and t2.

Referenced by QJsonArray::iterator::operator-(), QJsonArray::const_iterator::operator-(), QJsonObject::iterator::operator-(), and QJsonObject::const_iterator::operator-().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator+() [2/3]

timespec operator+ ( const timespec & t1,
int ms )
inline

Definition at line 166 of file qcore_unix_p.h.

◆ operator+() [3/3]

timespec operator+ ( const timespec & t1,
std::chrono::milliseconds msecs )
inline

Definition at line 159 of file qcore_unix_p.h.

References t1.

◆ operator+=() [1/3]

constexpr timespec & operator+= ( timespec & t1,
const timespec & t2 )
inlineconstexpr

Definition at line 112 of file qcore_unix_p.h.

References normalizedTimespec(), and t2.

+ Here is the call graph for this function:

◆ operator+=() [2/3]

timespec & operator+= ( timespec & t1,
int ms )
inline

Definition at line 153 of file qcore_unix_p.h.

References t1.

◆ operator+=() [3/3]

timespec & operator+= ( timespec & t1,
std::chrono::milliseconds msecs )
inline

Definition at line 147 of file qcore_unix_p.h.

References durationToTimespec(), and t1.

+ Here is the call graph for this function:

◆ operator-()

constexpr timespec operator- ( const timespec & t1,
const timespec & t2 )
inlineconstexpr

Definition at line 125 of file qcore_unix_p.h.

References normalizedTimespec(), OneSecAsNsecs, and t2.

+ Here is the call graph for this function:

◆ operator<()

constexpr bool operator< ( const timespec & t1,
const timespec & t2 )
inlineconstexpr

Definition at line 106 of file qcore_unix_p.h.

References t2.

◆ operator==()

constexpr bool operator== ( const timespec & t1,
const timespec & t2 )
inlineconstexpr

Definition at line 108 of file qcore_unix_p.h.

References t2.

◆ Q_DECLARE_TYPEINFO()

QT_BEGIN_NAMESPACE Q_DECLARE_TYPEINFO ( pollfd ,
Q_PRIMITIVE_TYPE  )

◆ qAbsTimespec()

timespec qAbsTimespec ( timespec ts)
inline

Definition at line 171 of file qcore_unix_p.h.

References normalizedTimespec(), and OneSecAsNsecs.

+ Here is the call graph for this function:

◆ qt_haveLinuxProcfs()

bool qt_haveLinuxProcfs ( )
inline

Definition at line 368 of file qcore_unix_p.h.

Referenced by bluetoothdVersion(), and QLockFilePrivate::processNameByPid().

+ Here is the caller graph for this function:

◆ qt_ignore_sigpipe()

Q_CORE_EXPORT void qt_ignore_sigpipe ( )
noexcept

Definition at line 23 of file qcore_unix.cpp.

References Q_BASIC_ATOMIC_INITIALIZER.

Referenced by qt_safe_sendmsg(), and qt_safe_write_nosignal().

+ Here is the caller graph for this function:

◆ qt_make_pollfd()

static struct pollfd qt_make_pollfd ( int fd,
short events )
inlinestatic

Definition at line 384 of file qcore_unix_p.h.

Referenced by QNativeSocketEnginePrivate::nativeSelect(), QThreadPipe::prepare(), and QEventDispatcherUNIX::processEvents().

+ Here is the caller graph for this function:

◆ qt_readlink()

QByteArray qt_readlink ( const char * path)

Definition at line 38 of file qcore_unix.cpp.

References PATH_MAX, QByteArray(), and Qt::Uninitialized.

Referenced by QFileSystemEngine::getLinkTarget(), QFileSystemEngine::getRawLinkPath(), QLockFilePrivate::processNameByPid(), and qAppFileName().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ qt_safe_close()

◆ qt_safe_dup()

static int qt_safe_dup ( int oldfd,
int atleast = 0,
int flags = FD_CLOEXEC )
inlinestatic

Definition at line 255 of file qcore_unix_p.h.

References Q_ASSERT, and ret.

Referenced by QKqueueFileSystemWatcherEngine::addPaths().

+ Here is the caller graph for this function:

◆ qt_safe_dup2()

static int qt_safe_dup2 ( int oldfd,
int newfd,
int flags = FD_CLOEXEC )
inlinestatic

Definition at line 276 of file qcore_unix_p.h.

References Q_ASSERT, QT_EINTR_LOOP, and ret.

◆ qt_safe_open()

◆ qt_safe_pipe()

static int qt_safe_pipe ( int pipefd[2],
int flags = 0 )
inlinestatic

Definition at line 226 of file qcore_unix_p.h.

References Q_ASSERT, and ret.

Referenced by QThreadPipe::init(), QtWaylandClient::QWaylandMimeData::retrieveData_sys(), and QtWaylandClient::EventThread::run().

+ Here is the caller graph for this function:

◆ qt_safe_poll()

Q_CORE_EXPORT int qt_safe_poll ( struct pollfd * fds,
nfds_t nfds,
QDeadlineTimer deadline )

Behaves as close to POSIX poll(2) as practical but may be implemented using select(2) where necessary. In that case, returns -1 and sets errno to EINVAL if passed any descriptor greater than or equal to FD_SETSIZE.

Definition at line 121 of file qcore_unix.cpp.

References deadline, durationToTimespec(), QDeadlineTimer::isForever(), QT_EINTR_LOOP, qt_ppoll(), QDeadlineTimer::remainingTimeAsDuration(), and ret.

Referenced by QNativeSocketEnginePrivate::nativeSelect(), and QEventDispatcherUNIX::processEvents().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ qt_safe_read()

static qint64 qt_safe_read ( int fd,
void * data,
qint64 maxlen )
inlinestatic

Definition at line 296 of file qcore_unix_p.h.

References QT_EINTR_LOOP, QT_READ, and ret.

Referenced by QSysInfo::bootUniqueId(), LeCmacCalculator::calculateMac(), QOpenGLProgramBinaryCache::load(), QSysInfo::machineUniqueId(), QNativeSocketEnginePrivate::nativeRead(), QLockFilePrivate::processNameByPid(), QBsdKeyboardHandler::readKeyboardData(), and QEvdevKeyboardHandler::readKeycode().

+ Here is the caller graph for this function:

◆ qt_safe_write()

static qint64 qt_safe_write ( int fd,
const void * data,
qint64 len )
inlinestatic

Definition at line 305 of file qcore_unix_p.h.

References QT_EINTR_LOOP, QT_WRITE, and ret.

Referenced by LeCmacCalculator::calculateMac(), qt_safe_write_nosignal(), qt_write_loop(), QThreadPipe::wakeUp(), and QBluetoothSocketPrivateBluez::writeData().

+ Here is the caller graph for this function:

◆ qt_safe_write_nosignal()

static qint64 qt_safe_write_nosignal ( int fd,
const void * data,
qint64 len )
inlinestatic

Definition at line 314 of file qcore_unix_p.h.

References qt_ignore_sigpipe(), and qt_safe_write().

Referenced by QNativeSocketEnginePrivate::nativeWrite().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ timespecToChrono()

template<typename Duration >
Duration timespecToChrono ( timespec ts)
inlinenoexcept

Definition at line 82 of file qcore_unix_p.h.

◆ timespecToChronoMs()

std::chrono::milliseconds timespecToChronoMs ( timespec ts)
inlinenoexcept

Definition at line 88 of file qcore_unix_p.h.

◆ timespecToTimeval()

timeval timespecToTimeval ( timespec ts)
inline

Definition at line 139 of file qcore_unix_p.h.

Referenced by qt_poll().

+ Here is the caller graph for this function:

Variable Documentation

◆ OneSecAsNsecs

constexpr auto OneSecAsNsecs = std::chrono::nanoseconds(std::chrono::seconds{ 1 }).count()
staticconstexpr

Definition at line 68 of file qcore_unix_p.h.

Referenced by normalizedTimespec(), operator-(), and qAbsTimespec().