summaryrefslogtreecommitdiffstats
path: root/src/network/socket/qlocalserver_win.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@theqtcompany.com>2016-03-21 09:02:57 +0100
committerLiang Qi <liang.qi@theqtcompany.com>2016-03-21 09:02:57 +0100
commit6cb8121a44ee0f94f2c9fcb075d1d3c802d8c5c7 (patch)
tree25822898b71068f820d25a9e8372dfb348190ec1 /src/network/socket/qlocalserver_win.cpp
parent96740193e1e0f0608f67660811a44b696924ad4c (diff)
parent2e02de165115c9d67ac343ff0960ed80f9c09bc8 (diff)
Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts: src/widgets/styles/qgtkstyle_p.cpp tests/auto/corelib/io/qtextstream/test/test.pro tests/auto/corelib/plugin/plugin.pro Change-Id: I512bc1b36acf3933ed2b96c00f476ee3819c1f4b
Diffstat (limited to 'src/network/socket/qlocalserver_win.cpp')
-rw-r--r--src/network/socket/qlocalserver_win.cpp70
1 files changed, 40 insertions, 30 deletions
diff --git a/src/network/socket/qlocalserver_win.cpp b/src/network/socket/qlocalserver_win.cpp
index dae1f82063..8cb3449343 100644
--- a/src/network/socket/qlocalserver_win.cpp
+++ b/src/network/socket/qlocalserver_win.cpp
@@ -198,6 +198,9 @@ bool QLocalServerPrivate::addListener()
memset(&listener.overlapped, 0, sizeof(listener.overlapped));
listener.overlapped.hEvent = eventHandle;
+
+ // Beware! ConnectNamedPipe will reset the eventHandle to non-signaled.
+ // Callers of addListener must check all listeners for connections.
if (!ConnectNamedPipe(listener.handle, &listener.overlapped)) {
switch (GetLastError()) {
case ERROR_IO_PENDING:
@@ -205,7 +208,6 @@ bool QLocalServerPrivate::addListener()
break;
case ERROR_PIPE_CONNECTED:
listener.connected = true;
- SetEvent(eventHandle);
break;
default:
CloseHandle(listener.handle);
@@ -257,6 +259,8 @@ bool QLocalServerPrivate::listen(const QString &name)
for (int i = 0; i < SYSTEM_MAX_PENDING_SOCKETS; ++i)
if (!addListener())
return false;
+
+ _q_onNewConnection();
return true;
}
@@ -270,37 +274,43 @@ void QLocalServerPrivate::_q_onNewConnection()
{
Q_Q(QLocalServer);
DWORD dummy;
-
- // Reset first, otherwise we could reset an event which was asserted
- // immediately after we checked the conn status.
- ResetEvent(eventHandle);
-
- // Testing shows that there is indeed absolutely no guarantee which listener gets
- // a client connection first, so there is no way around polling all of them.
- for (int i = 0; i < listeners.size(); ) {
- HANDLE handle = listeners[i].handle;
- if (listeners[i].connected
- || GetOverlappedResult(handle, &listeners[i].overlapped, &dummy, FALSE))
- {
- listeners.removeAt(i);
-
- addListener();
-
- if (pendingConnections.size() > maxPendingConnections)
- connectionEventNotifier->setEnabled(false);
-
- // Make this the last thing so connected slots can wreak the least havoc
- q->incomingConnection((quintptr)handle);
- } else {
- if (GetLastError() != ERROR_IO_INCOMPLETE) {
- q->close();
- setError(QLatin1String("QLocalServerPrivate::_q_onNewConnection"));
- return;
+ bool tryAgain;
+ do {
+ tryAgain = false;
+
+ // Reset first, otherwise we could reset an event which was asserted
+ // immediately after we checked the conn status.
+ ResetEvent(eventHandle);
+
+ // Testing shows that there is indeed absolutely no guarantee which listener gets
+ // a client connection first, so there is no way around polling all of them.
+ for (int i = 0; i < listeners.size(); ) {
+ HANDLE handle = listeners[i].handle;
+ if (listeners[i].connected
+ || GetOverlappedResult(handle, &listeners[i].overlapped, &dummy, FALSE))
+ {
+ listeners.removeAt(i);
+
+ addListener();
+
+ if (pendingConnections.size() > maxPendingConnections)
+ connectionEventNotifier->setEnabled(false);
+ else
+ tryAgain = true;
+
+ // Make this the last thing so connected slots can wreak the least havoc
+ q->incomingConnection((quintptr)handle);
+ } else {
+ if (GetLastError() != ERROR_IO_INCOMPLETE) {
+ q->close();
+ setError(QLatin1String("QLocalServerPrivate::_q_onNewConnection"));
+ return;
+ }
+
+ ++i;
}
-
- ++i;
}
- }
+ } while (tryAgain);
}
void QLocalServerPrivate::closeServer()