Clean up new poll code slightly
Change-Id: I046126ff69a77a50e79efb1b6ebb0fffef67ac8e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
e9802a1073
commit
bb747268ed
@ -142,7 +142,7 @@ struct QProcessPoller
|
|||||||
QProcessPoller::QProcessPoller(const QProcessPrivate &proc)
|
QProcessPoller::QProcessPoller(const QProcessPrivate &proc)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < n_pfds; i++)
|
for (int i = 0; i < n_pfds; i++)
|
||||||
pfds[i] = { -1, POLLIN, 0 };
|
pfds[i] = qt_make_pollfd(-1, POLLIN);
|
||||||
|
|
||||||
stdoutPipe().fd = proc.stdoutChannel.pipe[0];
|
stdoutPipe().fd = proc.stdoutChannel.pipe[0];
|
||||||
stderrPipe().fd = proc.stderrChannel.pipe[0];
|
stderrPipe().fd = proc.stderrChannel.pipe[0];
|
||||||
@ -873,7 +873,7 @@ bool QProcessPrivate::waitForStarted(int msecs)
|
|||||||
childStartedPipe[0]);
|
childStartedPipe[0]);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pollfd pfd = { childStartedPipe[0], POLLIN, 0 };
|
pollfd pfd = qt_make_pollfd(childStartedPipe[0], POLLIN);
|
||||||
|
|
||||||
if (qt_poll_msecs(&pfd, 1, msecs) == 0) {
|
if (qt_poll_msecs(&pfd, 1, msecs) == 0) {
|
||||||
setError(QProcess::Timedout);
|
setError(QProcess::Timedout);
|
||||||
@ -1036,7 +1036,7 @@ bool QProcessPrivate::waitForFinished(int msecs)
|
|||||||
|
|
||||||
bool QProcessPrivate::waitForWrite(int msecs)
|
bool QProcessPrivate::waitForWrite(int msecs)
|
||||||
{
|
{
|
||||||
pollfd pfd = { stdinChannel.pipe[1], POLLOUT, 0 };
|
pollfd pfd = qt_make_pollfd(stdinChannel.pipe[1], POLLOUT);
|
||||||
return qt_poll_msecs(&pfd, 1, msecs < 0 ? 0 : msecs) == 1;
|
return qt_poll_msecs(&pfd, 1, msecs < 0 ? 0 : msecs) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,18 +184,4 @@ int qt_safe_poll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int qt_poll_msecs(pollfd *fds, nfds_t nfds, int timeout)
|
|
||||||
{
|
|
||||||
timespec ts, *pts = Q_NULLPTR;
|
|
||||||
|
|
||||||
if (timeout >= 0) {
|
|
||||||
ts.tv_sec = timeout / 1000;
|
|
||||||
ts.tv_nsec = (timeout % 1000) * 1000 * 1000;
|
|
||||||
|
|
||||||
pts = &ts;
|
|
||||||
}
|
|
||||||
|
|
||||||
return qt_safe_poll(fds, nfds, pts);
|
|
||||||
}
|
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -326,7 +326,24 @@ void qt_nanosleep(timespec amount);
|
|||||||
|
|
||||||
Q_CORE_EXPORT int qt_safe_poll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout_ts);
|
Q_CORE_EXPORT int qt_safe_poll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout_ts);
|
||||||
|
|
||||||
int qt_poll_msecs(struct pollfd *fds, nfds_t nfds, int timeout);
|
static inline int qt_poll_msecs(struct pollfd *fds, nfds_t nfds, int timeout)
|
||||||
|
{
|
||||||
|
timespec ts, *pts = Q_NULLPTR;
|
||||||
|
|
||||||
|
if (timeout >= 0) {
|
||||||
|
ts.tv_sec = timeout / 1000;
|
||||||
|
ts.tv_nsec = (timeout % 1000) * 1000 * 1000;
|
||||||
|
pts = &ts;
|
||||||
|
}
|
||||||
|
|
||||||
|
return qt_safe_poll(fds, nfds, pts);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline struct pollfd qt_make_pollfd(int fd, short events)
|
||||||
|
{
|
||||||
|
struct pollfd pfd = { fd, events, 0 };
|
||||||
|
return pfd;
|
||||||
|
}
|
||||||
|
|
||||||
Q_CORE_EXPORT int qt_safe_select(int nfds, fd_set *fdread, fd_set *fdwrite, fd_set *fdexcept,
|
Q_CORE_EXPORT int qt_safe_select(int nfds, fd_set *fdread, fd_set *fdwrite, fd_set *fdexcept,
|
||||||
const struct timespec *tv);
|
const struct timespec *tv);
|
||||||
|
@ -89,12 +89,6 @@ static const char *socketType(QSocketNotifier::Type type)
|
|||||||
Q_UNREACHABLE();
|
Q_UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
static pollfd make_pollfd(int fd, short events)
|
|
||||||
{
|
|
||||||
pollfd pfd = { fd, events, 0 };
|
|
||||||
return pfd;
|
|
||||||
}
|
|
||||||
|
|
||||||
QThreadPipe::QThreadPipe()
|
QThreadPipe::QThreadPipe()
|
||||||
{
|
{
|
||||||
fds[0] = -1;
|
fds[0] = -1;
|
||||||
@ -173,7 +167,7 @@ bool QThreadPipe::init()
|
|||||||
|
|
||||||
pollfd QThreadPipe::prepare() const
|
pollfd QThreadPipe::prepare() const
|
||||||
{
|
{
|
||||||
return make_pollfd(fds[0], POLLIN);
|
return qt_make_pollfd(fds[0], POLLIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QThreadPipe::wakeUp()
|
void QThreadPipe::wakeUp()
|
||||||
@ -491,7 +485,7 @@ bool QEventDispatcherUNIX::processEvents(QEventLoop::ProcessEventsFlags flags)
|
|||||||
|
|
||||||
if (include_notifiers)
|
if (include_notifiers)
|
||||||
for (auto it = d->socketNotifiers.cbegin(); it != d->socketNotifiers.cend(); ++it)
|
for (auto it = d->socketNotifiers.cbegin(); it != d->socketNotifiers.cend(); ++it)
|
||||||
d->pollfds.append(make_pollfd(it.key(), it.value().events()));
|
d->pollfds.append(qt_make_pollfd(it.key(), it.value().events()));
|
||||||
|
|
||||||
// This must be last, as it's popped off the end below
|
// This must be last, as it's popped off the end below
|
||||||
d->pollfds.append(d->threadPipe.prepare());
|
d->pollfds.append(d->threadPipe.prepare());
|
||||||
|
@ -283,20 +283,9 @@ void QLocalServerPrivate::_q_onNewConnection()
|
|||||||
|
|
||||||
void QLocalServerPrivate::waitForNewConnection(int msec, bool *timedOut)
|
void QLocalServerPrivate::waitForNewConnection(int msec, bool *timedOut)
|
||||||
{
|
{
|
||||||
struct timespec tv, *ptv = nullptr;
|
pollfd pfd = qt_make_pollfd(listenSocket, POLLIN);
|
||||||
|
|
||||||
if (msec >= 0) {
|
switch (qt_poll_msecs(&pfd, 1, msec)) {
|
||||||
tv.tv_sec = msec / 1000;
|
|
||||||
tv.tv_nsec = (msec % 1000) * 1000 * 1000;
|
|
||||||
ptv = &tv;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct pollfd pfd;
|
|
||||||
pfd.fd = listenSocket;
|
|
||||||
pfd.events = POLLIN;
|
|
||||||
pfd.revents = 0;
|
|
||||||
|
|
||||||
switch (qt_safe_poll(&pfd, 1, ptv)) {
|
|
||||||
case 0:
|
case 0:
|
||||||
if (timedOut)
|
if (timedOut)
|
||||||
*timedOut = true;
|
*timedOut = true;
|
||||||
|
@ -1209,18 +1209,7 @@ int QNativeSocketEnginePrivate::nativeSelect(int timeout, bool selectForRead) co
|
|||||||
int QNativeSocketEnginePrivate::nativeSelect(int timeout, bool checkRead, bool checkWrite,
|
int QNativeSocketEnginePrivate::nativeSelect(int timeout, bool checkRead, bool checkWrite,
|
||||||
bool *selectForRead, bool *selectForWrite) const
|
bool *selectForRead, bool *selectForWrite) const
|
||||||
{
|
{
|
||||||
struct timespec tv, *ptv = nullptr;
|
pollfd pfd = qt_make_pollfd(socketDescriptor, 0);
|
||||||
|
|
||||||
if (timeout >= 0) {
|
|
||||||
tv.tv_sec = timeout / 1000;
|
|
||||||
tv.tv_nsec = (timeout % 1000) * 1000 * 1000;
|
|
||||||
ptv = &tv;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct pollfd pfd;
|
|
||||||
pfd.fd = socketDescriptor;
|
|
||||||
pfd.events = 0;
|
|
||||||
pfd.revents = 0;
|
|
||||||
|
|
||||||
if (checkRead)
|
if (checkRead)
|
||||||
pfd.events |= POLLIN;
|
pfd.events |= POLLIN;
|
||||||
@ -1228,7 +1217,7 @@ int QNativeSocketEnginePrivate::nativeSelect(int timeout, bool checkRead, bool c
|
|||||||
if (checkWrite)
|
if (checkWrite)
|
||||||
pfd.events |= POLLOUT;
|
pfd.events |= POLLOUT;
|
||||||
|
|
||||||
const int ret = qt_safe_poll(&pfd, 1, ptv);
|
const int ret = qt_poll_msecs(&pfd, 1, timeout);
|
||||||
|
|
||||||
if (ret <= 0)
|
if (ret <= 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user