aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@theqtcompany.com>2015-06-16 13:40:08 +0200
committerUlf Hermann <ulf.hermann@theqtcompany.com>2015-08-04 13:34:48 +0000
commita010f3a8f92a9a364e9d17d12b06074fde6f8a17 (patch)
tree33a3a91f63d8daa4a5a939a4af4e29812c803bc0 /src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.cpp
parent31291359a327c5ffa6aa3aff76b62491782408d7 (diff)
Deduplicate debug server connection code.
The packet protocol can be part of the server, now that the server is not part of QtQml anymore. This enables us to remove some duplicated code from the connections. As an added benefit, with more control over the sending process, QQmlDebugServer can now efficiently send single packets, without creating a QList<QByteArray> first. Change-Id: I13cc831e254c02b737e64816d6d3ab051d760995 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.cpp')
-rw-r--r--src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.cpp61
1 files changed, 8 insertions, 53 deletions
diff --git a/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.cpp b/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.cpp
index 4333a9c7e9..7734e5ed0d 100644
--- a/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.cpp
+++ b/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.cpp
@@ -32,7 +32,6 @@
****************************************************************************/
#include "qtcpserverconnection.h"
-#include "qpacketprotocol.h"
#include "qqmldebugserver.h"
#include <QtCore/qplugin.h>
@@ -50,7 +49,6 @@ public:
bool block;
QString hostaddress;
QTcpSocket *socket;
- QPacketProtocol *protocol;
QTcpServer *tcpServer;
QQmlDebugServer *debugServer;
@@ -61,7 +59,6 @@ QTcpServerConnectionPrivate::QTcpServerConnectionPrivate() :
portTo(0),
block(false),
socket(0),
- protocol(0),
tcpServer(0),
debugServer(0)
{
@@ -92,22 +89,6 @@ bool QTcpServerConnection::isConnected() const
return d->socket && d->socket->state() == QTcpSocket::ConnectedState;
}
-void QTcpServerConnection::send(const QList<QByteArray> &messages)
-{
- Q_D(QTcpServerConnection);
-
- if (!isConnected()
- || !d->protocol || !d->socket)
- return;
-
- foreach (const QByteArray &message, messages) {
- QPacket pack;
- pack.writeRawData(message.data(), message.length());
- d->protocol->send(pack);
- }
- d->socket->flush();
-}
-
void QTcpServerConnection::disconnect()
{
Q_D(QTcpServerConnection);
@@ -120,19 +101,10 @@ void QTcpServerConnection::disconnect()
}
}
- // protocol might still be processing packages at this point
- d->protocol->deleteLater();
- d->protocol = 0;
d->socket->deleteLater();
d->socket = 0;
}
-bool QTcpServerConnection::waitForMessage()
-{
- Q_D(QTcpServerConnection);
- return d->protocol->waitForReadyRead(-1);
-}
-
bool QTcpServerConnection::setPortRange(int portFrom, int portTo, bool block,
const QString &hostaddress)
{
@@ -158,6 +130,13 @@ void QTcpServerConnection::waitForConnection()
d->tcpServer->waitForNewConnection(-1);
}
+void QTcpServerConnection::flush()
+{
+ Q_D(QTcpServerConnection);
+ if (d->socket)
+ d->socket->flush();
+}
+
bool QTcpServerConnection::listen()
{
Q_D(QTcpServerConnection);
@@ -193,19 +172,6 @@ bool QTcpServerConnection::listen()
}
}
-
-void QTcpServerConnection::readyRead()
-{
- Q_D(QTcpServerConnection);
- if (!d->protocol)
- return;
-
- QPacket packet = d->protocol->read();
-
- QByteArray content = packet.data();
- d->debugServer->receiveMessage(content);
-}
-
void QTcpServerConnection::newConnection()
{
Q_D(QTcpServerConnection);
@@ -220,18 +186,7 @@ void QTcpServerConnection::newConnection()
delete d->socket;
d->socket = d->tcpServer->nextPendingConnection();
d->socket->setParent(this);
- d->protocol = new QPacketProtocol(d->socket, this);
- QObject::connect(d->protocol, SIGNAL(readyRead()), this, SLOT(readyRead()));
- QObject::connect(d->protocol, SIGNAL(invalidPacket()), this, SLOT(invalidPacket()));
-
- if (d->block) {
- d->protocol->waitForReadyRead(-1);
- }
-}
-
-void QTcpServerConnection::invalidPacket()
-{
- qWarning("QML Debugger: Received a corrupted packet! Giving up ...");
+ d->debugServer->setDevice(d->socket);
}
QT_END_NAMESPACE