Commit 35ed93fe authored by Ulf Hermann's avatar Ulf Hermann
Browse files

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: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
parent e3c16259
......@@ -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()
......
......@@ -55,6 +55,7 @@ public:
~QmlDebugConnection();
void connectToHost(const QString &hostName, quint16 port);
QAbstractSocket::SocketState socketState() const;
bool isOpen() const;
bool isConnecting() const;
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment