diff options
author | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2015-11-23 10:16:47 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2015-11-26 11:40:51 +0000 |
commit | 35ed93fe2d8fbc2d5b2531edb4f3b32be55457ce (patch) | |
tree | f82a574dd925707bcc961331e96427c0c909575f | |
parent | e3c16259ed5297a3ee707d0aeade985ae103992e (diff) |
QmlProfiler: replace TCP connections after 200ms of failing to connect
Sometimes it takes very long to establish a TCP connection to the debug
server. If the connection hasn't been established after 200ms we
probably don't want to wait for it any longer. If, however, the TCP
connection is there and the "hello" hasn't arrived yet, we keep the
connection in order not to trigger an unexpected state in the
application.
Change-Id: I1a64493fefc759f526cdebff434a2557077f9246
Task-number: QTCREATORBUG-15383
Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
-rw-r--r-- | src/libs/qmldebug/qmldebugclient.cpp | 9 | ||||
-rw-r--r-- | src/libs/qmldebug/qmldebugclient.h | 1 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/qmlprofilerclientmanager.cpp | 11 |
3 files changed, 21 insertions, 0 deletions
diff --git a/src/libs/qmldebug/qmldebugclient.cpp b/src/libs/qmldebug/qmldebugclient.cpp index 2f5b7976cd..126830ba13 100644 --- a/src/libs/qmldebug/qmldebugclient.cpp +++ b/src/libs/qmldebug/qmldebugclient.cpp @@ -334,6 +334,15 @@ void QmlDebugConnection::connectToHost(const QString &hostName, quint16 port) socket->connectToHost(hostName, port); } +QAbstractSocket::SocketState QmlDebugConnection::socketState() const +{ + // TODO: when merging into master, add clause for local socket + if (QAbstractSocket *socket = qobject_cast<QAbstractSocket *>(d->device)) + return socket->state(); + else + return QAbstractSocket::UnconnectedState; +} + // QmlDebugClientPrivate::QmlDebugClientPrivate() diff --git a/src/libs/qmldebug/qmldebugclient.h b/src/libs/qmldebug/qmldebugclient.h index 01c871ba09..fdee2f290e 100644 --- a/src/libs/qmldebug/qmldebugclient.h +++ b/src/libs/qmldebug/qmldebugclient.h @@ -55,6 +55,7 @@ public: ~QmlDebugConnection(); void connectToHost(const QString &hostName, quint16 port); + QAbstractSocket::SocketState socketState() const; bool isOpen() const; bool isConnecting() const; diff --git a/src/plugins/qmlprofiler/qmlprofilerclientmanager.cpp b/src/plugins/qmlprofiler/qmlprofilerclientmanager.cpp index a355955f5b..753a389d33 100644 --- a/src/plugins/qmlprofiler/qmlprofilerclientmanager.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerclientmanager.cpp @@ -242,6 +242,17 @@ void QmlProfilerClientManager::tryToConnect() if (d->connection && d->connection->isOpen()) { d->connectionTimer.stop(); d->connectionAttempts = 0; + } else if (d->connection && + d->connection->socketState() != QAbstractSocket::ConnectedState) { + // Replace the connection after trying for some time. On some operating systems (OSX) the + // very first connection to a TCP server takes a very long time to get established. + + // delete directly here, so that any pending events aren't delivered. We don't want the + // connection first to be established and then torn down again. + delete d->connection; + d->connection = 0; + connectClient(d->tcpPort); + connectToClient(); } else if (d->connectionAttempts == 50) { d->connectionTimer.stop(); d->connectionAttempts = 0; |