diff options
author | kh1 <karsten.heimrich@digia.com> | 2014-06-03 15:35:37 +0200 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@digia.com> | 2014-06-03 15:48:08 +0200 |
commit | e07968ebb99b7fe4e67c0470ec486a92816036d5 (patch) | |
tree | ad7e3bf5d95cae2ca57de0b745060f7276c72259 /src | |
parent | 22fb61b60c0686795f9671789ab3393da6c22987 (diff) |
We need to pass the socket to the connect function.
The keep alive thread does try to delete the socket it gets
from the connect method, but since the socket was created in
a different thread and we will hit the:
"Socket notifiers cannot be disabled from another thread" warning.
Change-Id: Ibafcd67f8cdb51b365c3ef230f1ebd447bdd306a
Reviewed-by: Niels Weber <niels.weber@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/installer/remoteclient.cpp | 13 | ||||
-rw-r--r-- | src/libs/installer/remoteclient.h | 2 | ||||
-rw-r--r-- | src/libs/installer/remoteclient_p.h | 17 | ||||
-rw-r--r-- | src/libs/installer/remoteobject.cpp | 5 |
4 files changed, 19 insertions, 18 deletions
diff --git a/src/libs/installer/remoteclient.cpp b/src/libs/installer/remoteclient.cpp index 60ccb3409..fed7ecc6c 100644 --- a/src/libs/installer/remoteclient.cpp +++ b/src/libs/installer/remoteclient.cpp @@ -88,14 +88,13 @@ void RemoteClient::init(quint16 port, const QHostAddress &address, Mode mode) d->init(port, address, mode); } -QTcpSocket *RemoteClient::connect() const +bool RemoteClient::connect(QTcpSocket *socket) const { Q_D(const RemoteClient); if (d->m_quit) - return 0; + return false; int tries = 3; - QScopedPointer<QTcpSocket> socket(new QTcpSocket); while ((tries > 0) && (!d->m_quit)) { socket->connectToHost(d->m_address, d->m_port); @@ -108,10 +107,10 @@ QTcpSocket *RemoteClient::connect() const continue; } if ((socket->state() != QAbstractSocket::ConnectedState) || d->m_quit) - return 0; + return false; QDataStream stream; - stream.setDevice(socket.data()); + stream.setDevice(socket); stream << QString::fromLatin1(Protocol::Authorize) << d->m_key; socket->waitForBytesWritten(-1); @@ -121,9 +120,9 @@ QTcpSocket *RemoteClient::connect() const quint32 size; stream >> size; bool authorized; stream >> authorized; if (authorized && (!d->m_quit)) - return socket.take(); + return true; } - return 0; + return false; } bool RemoteClient::isActive() const diff --git a/src/libs/installer/remoteclient.h b/src/libs/installer/remoteclient.h index ff92a3dda..1ef8eba0b 100644 --- a/src/libs/installer/remoteclient.h +++ b/src/libs/installer/remoteclient.h @@ -73,7 +73,7 @@ public: }; static RemoteClient &instance(); - QTcpSocket *connect() const; + bool connect(QTcpSocket *socket) const; void init(quint16 port, const QHostAddress &address, Mode mode); QString authorizationKey() const; diff --git a/src/libs/installer/remoteclient_p.h b/src/libs/installer/remoteclient_p.h index 5f7dc0bea..ed47d0d53 100644 --- a/src/libs/installer/remoteclient_p.h +++ b/src/libs/installer/remoteclient_p.h @@ -90,7 +90,8 @@ private slots: { // Try to connect to the server. If we succeed the server side running watchdog gets // restarted and the server keeps running for another 30 seconds. - QScopedPointer<QTcpSocket> socket(m_client->connect()); + QTcpSocket socket; + m_client->connect(&socket); } m_timer->start(1000); @@ -134,9 +135,9 @@ public: if (m_mode == RemoteClient::Release) { QObject *const object = new KeepAliveObject(q_ptr); object->moveToThread(&m_thread); + QObject::connect(&m_thread, SIGNAL(started()), object, SLOT(run())); QObject::connect(&m_thread, SIGNAL(finished()), object, SLOT(deleteLater())); m_thread.start(); - QTimer::singleShot(0, object, SLOT(run())); } else if (mode == RemoteClient::Debug) { m_active = true; m_serverStarted = true; @@ -188,8 +189,8 @@ public: // 30 seconds ought to be enough for the app to start while (m_serverStarting && m_serverStarted && t.elapsed() < 30000) { Q_Q(RemoteClient); - QScopedPointer<QTcpSocket> socket(q->connect()); - if (socket) + QTcpSocket socket; + if (q->connect(&socket)) m_serverStarting = false; } } @@ -206,13 +207,13 @@ public: return; Q_Q(RemoteClient); - QScopedPointer<QTcpSocket> socket(q->connect()); - if (socket) { - QDataStream stream(socket.data()); + QTcpSocket socket; + if (q->connect(&socket)) { + QDataStream stream(&socket); stream << QString::fromLatin1(Protocol::Authorize); stream << m_key; stream << QString::fromLatin1(Protocol::Shutdown); - socket->flush(); + socket.flush(); } m_serverStarted = false; } diff --git a/src/libs/installer/remoteobject.cpp b/src/libs/installer/remoteobject.cpp index 2c1aa275a..508c9d609 100644 --- a/src/libs/installer/remoteobject.cpp +++ b/src/libs/installer/remoteobject.cpp @@ -75,10 +75,11 @@ bool RemoteObject::connectToServer(const QVariantList &arguments) if (m_socket) m_socket->deleteLater(); - m_socket = RemoteClient::instance().connect(); - if (!m_socket) + QScopedPointer<QTcpSocket> socket(new QTcpSocket); + if (!RemoteClient::instance().connect(socket.data())) return false; + m_socket = socket.take(); m_stream.setDevice(m_socket); m_stream << QString::fromLatin1(Protocol::Create) << m_type; foreach (const QVariant &arg, arguments) |