From 35ed93fe2d8fbc2d5b2531edb4f3b32be55457ce Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 23 Nov 2015 10:16:47 +0100 Subject: [PATCH] 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 --- src/libs/qmldebug/qmldebugclient.cpp | 9 +++++++++ src/libs/qmldebug/qmldebugclient.h | 1 + src/plugins/qmlprofiler/qmlprofilerclientmanager.cpp | 11 +++++++++++ 3 files changed, 21 insertions(+) diff --git a/src/libs/qmldebug/qmldebugclient.cpp b/src/libs/qmldebug/qmldebugclient.cpp index 2f5b7976cd7..126830ba13f 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(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 01c871ba09c..fdee2f290e9 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 a355955f5bd..753a389d33c 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;