Use 0/nullptr to indicate invalid Windows event handle in QLocalServer
The CreateEvent function returns NULL/nullptr if it failed, not INVALID_HANDLE_VALUE(-1). Change-Id: I7fb94061f4e14c014bf63acb53d3eee8f295eb66 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
0b7ff3d0a7
commit
604b6d60d0
@ -197,7 +197,7 @@ qintptr QLocalServer::socketDescriptor() const
|
|||||||
return d->tcpServer.socketDescriptor();
|
return d->tcpServer.socketDescriptor();
|
||||||
#elif defined(Q_OS_WIN)
|
#elif defined(Q_OS_WIN)
|
||||||
const auto handle = d->connectionEventNotifier->handle();
|
const auto handle = d->connectionEventNotifier->handle();
|
||||||
return handle != INVALID_HANDLE_VALUE ? qintptr(handle) : -1;
|
return handle ? qintptr(handle) : -1;
|
||||||
#else
|
#else
|
||||||
return d->socketNotifier->socket();
|
return d->socketNotifier->socket();
|
||||||
#endif
|
#endif
|
||||||
|
@ -76,7 +76,7 @@ public:
|
|||||||
bool addListener();
|
bool addListener();
|
||||||
|
|
||||||
std::vector<std::unique_ptr<Listener>> listeners;
|
std::vector<std::unique_ptr<Listener>> listeners;
|
||||||
HANDLE eventHandle;
|
HANDLE eventHandle = nullptr;
|
||||||
QWinEventNotifier *connectionEventNotifier;
|
QWinEventNotifier *connectionEventNotifier;
|
||||||
#else
|
#else
|
||||||
void setError(const QString &function);
|
void setError(const QString &function);
|
||||||
|
@ -215,7 +215,7 @@ bool QLocalServerPrivate::listen(const QString &name)
|
|||||||
// Use only one event for all listeners of one socket.
|
// Use only one event for all listeners of one socket.
|
||||||
// The idea is that listener events are rare, so polling all listeners once in a while is
|
// The idea is that listener events are rare, so polling all listeners once in a while is
|
||||||
// cheap compared to waiting for N additional events in each iteration of the main loop.
|
// cheap compared to waiting for N additional events in each iteration of the main loop.
|
||||||
eventHandle = CreateEvent(NULL, TRUE, FALSE, NULL);
|
eventHandle = CreateEvent(NULL, TRUE, FALSE, NULL); // If the function fails, the return value is NULL
|
||||||
connectionEventNotifier = new QWinEventNotifier(eventHandle , q);
|
connectionEventNotifier = new QWinEventNotifier(eventHandle , q);
|
||||||
q->connect(connectionEventNotifier, SIGNAL(activated(HANDLE)), q, SLOT(_q_onNewConnection()));
|
q->connect(connectionEventNotifier, SIGNAL(activated(HANDLE)), q, SLOT(_q_onNewConnection()));
|
||||||
|
|
||||||
@ -282,6 +282,7 @@ void QLocalServerPrivate::closeServer()
|
|||||||
connectionEventNotifier->deleteLater();
|
connectionEventNotifier->deleteLater();
|
||||||
connectionEventNotifier = 0;
|
connectionEventNotifier = 0;
|
||||||
CloseHandle(eventHandle);
|
CloseHandle(eventHandle);
|
||||||
|
eventHandle = nullptr;
|
||||||
for (size_t i = 0; i < listeners.size(); ++i)
|
for (size_t i = 0; i < listeners.size(); ++i)
|
||||||
CloseHandle(listeners[i]->handle);
|
CloseHandle(listeners[i]->handle);
|
||||||
listeners.clear();
|
listeners.clear();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user