forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -334,6 +334,15 @@ void QmlDebugConnection::connectToHost(const QString &hostName, quint16 port)
|
|||||||
socket->connectToHost(hostName, 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()
|
QmlDebugClientPrivate::QmlDebugClientPrivate()
|
||||||
|
@@ -55,6 +55,7 @@ public:
|
|||||||
~QmlDebugConnection();
|
~QmlDebugConnection();
|
||||||
|
|
||||||
void connectToHost(const QString &hostName, quint16 port);
|
void connectToHost(const QString &hostName, quint16 port);
|
||||||
|
QAbstractSocket::SocketState socketState() const;
|
||||||
|
|
||||||
bool isOpen() const;
|
bool isOpen() const;
|
||||||
bool isConnecting() const;
|
bool isConnecting() const;
|
||||||
|
@@ -242,6 +242,17 @@ void QmlProfilerClientManager::tryToConnect()
|
|||||||
if (d->connection && d->connection->isOpen()) {
|
if (d->connection && d->connection->isOpen()) {
|
||||||
d->connectionTimer.stop();
|
d->connectionTimer.stop();
|
||||||
d->connectionAttempts = 0;
|
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) {
|
} else if (d->connectionAttempts == 50) {
|
||||||
d->connectionTimer.stop();
|
d->connectionTimer.stop();
|
||||||
d->connectionAttempts = 0;
|
d->connectionAttempts = 0;
|
||||||
|
Reference in New Issue
Block a user