diff options
author | Peter Hartmann <peter.hartmann@nokia.com> | 2009-10-28 13:14:25 (GMT) |
---|---|---|
committer | Peter Hartmann <peter.hartmann@nokia.com> | 2009-10-28 14:50:41 (GMT) |
commit | 138e8c17767959c183b3e00e3fb364ab5b6fbdfd (patch) | |
tree | 95252fb9f139efe67c304a5cc47bd708b201d750 /src/network/socket | |
parent | 5b4b6b2be7b901ef9a29c37431998034730fa3d3 (diff) | |
download | Qt-138e8c17767959c183b3e00e3fb364ab5b6fbdfd.zip Qt-138e8c17767959c183b3e00e3fb364ab5b6fbdfd.tar.gz Qt-138e8c17767959c183b3e00e3fb364ab5b6fbdfd.tar.bz2 |
QLocalServer: block indefinitely when timeout value is -1
... as described in the documentation. Furthermore:
* use qt_safe_select to timeout correctly
* return immediately when timeout value is 0
Reviewed-by: Oswald Buddenhagen
Diffstat (limited to 'src/network/socket')
-rw-r--r-- | src/network/socket/qlocalserver_unix.cpp | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/src/network/socket/qlocalserver_unix.cpp b/src/network/socket/qlocalserver_unix.cpp index 5ffe0c0..e09e547 100644 --- a/src/network/socket/qlocalserver_unix.cpp +++ b/src/network/socket/qlocalserver_unix.cpp @@ -216,24 +216,14 @@ void QLocalServerPrivate::waitForNewConnection(int msec, bool *timedOut) timeout.tv_sec = msec / 1000; timeout.tv_usec = (msec % 1000) * 1000; - // timeout can not be 0 or else select will return an error. - if (0 == msec) - timeout.tv_usec = 1000; - int result = -1; - // on Linux timeout will be updated by select, but _not_ on other systems. - QTime timer; - timer.start(); - while (pendingConnections.isEmpty() && (-1 == msec || timer.elapsed() < msec)) { - result = ::select(listenSocket + 1, &readfds, 0, 0, &timeout); - if (-1 == result && errno != EINTR) { - setError(QLatin1String("QLocalServer::waitForNewConnection")); - closeServer(); - break; - } - if (result > 0) - _q_onNewConnection(); + result = qt_safe_select(listenSocket + 1, &readfds, 0, 0, (msec == -1) ? 0 : &timeout); + if (-1 == result) { + setError(QLatin1String("QLocalServer::waitForNewConnection")); + closeServer(); } + if (result > 0) + _q_onNewConnection(); if (timedOut) *timedOut = (result == 0); } |