Unix platforms: Use qt_safe_poll in QLocalServer

Change-Id: If9f0c1a0089b16729c20c0e05feca58a514d3e25
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Louai Al-Khanji 2015-10-19 15:25:02 +03:00
parent d28bb50b25
commit a0f9ee5dca

View File

@ -283,24 +283,39 @@ void QLocalServerPrivate::_q_onNewConnection()
void QLocalServerPrivate::waitForNewConnection(int msec, bool *timedOut) void QLocalServerPrivate::waitForNewConnection(int msec, bool *timedOut)
{ {
fd_set readfds; struct timespec tv, *ptv = nullptr;
FD_ZERO(&readfds);
FD_SET(listenSocket, &readfds);
struct timespec timeout; if (msec >= 0) {
timeout.tv_sec = msec / 1000; tv.tv_sec = msec / 1000;
timeout.tv_nsec = (msec % 1000) * 1000 * 1000; tv.tv_nsec = (msec % 1000) * 1000 * 1000;
ptv = &tv;
}
int result = -1; struct pollfd pfd;
result = qt_safe_select(listenSocket + 1, &readfds, 0, 0, (msec == -1) ? 0 : &timeout); pfd.fd = listenSocket;
if (-1 == result) { pfd.events = POLLIN;
pfd.revents = 0;
switch (qt_safe_poll(&pfd, 1, ptv)) {
case 0:
if (timedOut)
*timedOut = true;
return;
break;
default:
if ((pfd.revents & POLLNVAL) == 0) {
_q_onNewConnection();
return;
}
errno = EBADF;
// FALLTHROUGH
case -1:
setError(QLatin1String("QLocalServer::waitForNewConnection")); setError(QLatin1String("QLocalServer::waitForNewConnection"));
closeServer(); closeServer();
break;
} }
if (result > 0)
_q_onNewConnection();
if (timedOut)
*timedOut = (result == 0);
} }
void QLocalServerPrivate::setError(const QString &function) void QLocalServerPrivate::setError(const QString &function)