bail out early in QWinOverlappedIoNotifier::waitForNotified

Calling waitForNotified on an uninitialized notifier will print a
warning and return false. The autotest has been adjusted.

Change-Id: I85e18d6d0a8a5462e1a5d451613add941d89b5fb
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
bb10
Joerg Bornemann 2013-07-04 14:45:36 +02:00 committed by The Qt Project
parent a4478b2896
commit 3f605c8b45
2 changed files with 7 additions and 1 deletions

View File

@ -122,6 +122,8 @@ public:
mutex.unlock();
}
using QThread::isRunning;
protected:
void run()
{
@ -216,6 +218,11 @@ void QWinOverlappedIoNotifier::setEnabled(bool enabled)
*/
bool QWinOverlappedIoNotifier::waitForNotified(int msecs, OVERLAPPED *overlapped)
{
if (!iocp->isRunning()) {
qWarning("Called QWinOverlappedIoNotifier::waitForNotified on inactive notifier.");
return false;
}
forever {
DWORD result = WaitForSingleObject(hSemaphore, msecs == -1 ? INFINITE : DWORD(msecs));
if (result == WAIT_OBJECT_0) {

View File

@ -175,7 +175,6 @@ void tst_QWinOverlappedIoNotifier::waitForNotified()
HANDLE hFile = CreateFile(reinterpret_cast<const wchar_t*>(fileName.utf16()),
GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
QCOMPARE(notifier.waitForNotified(0, 0), false);
notifier.setHandle(hFile);
notifier.setEnabled(true);
QCOMPARE(notifier.waitForNotified(100, 0), false);