Commit 93c157e3 authored by Ulf Hermann's avatar Ulf Hermann

QmlDebug: Allow connecting through a local socket

This removes the necessity for listening to debug messages, as the
server is created by QtCreator then. Also, most of the time the
connections are local anyway, and TCP is a waste for that.

Change-Id: Ie5e1d7ba55dbda035a9ea7432f3af13915813de9
Reviewed-by: default avatarJoerg Bornemann <joerg.bornemann@theqtcompany.com>
parent 6b2cad3e
......@@ -35,6 +35,8 @@
#include <qdebug.h>
#include <qstringlist.h>
#include <qnetworkproxy.h>
#include <qlocalserver.h>
#include <qlocalsocket.h>
namespace QmlDebug {
......@@ -58,6 +60,7 @@ class QmlDebugConnectionPrivate
public:
QmlDebugConnectionPrivate();
QPacketProtocol *protocol;
QLocalServer *server;
QIODevice *device; // Currently a QTcpSocket
bool gotHello;
......@@ -371,6 +374,46 @@ void QmlDebugConnection::connectToHost(const QString &hostName, quint16 port)
socket->connectToHost(hostName, port);
}
void QmlDebugConnection::startLocalServer(const QString &fileName)
{
Q_D(QmlDebugConnection);
if (d->gotHello)
close();
if (d->server)
d->server->deleteLater();
d->server = new QLocalServer(this);
// QueuedConnection so that waitForNewConnection() returns true.
connect(d->server, SIGNAL(newConnection()), this, SLOT(newConnection()), Qt::QueuedConnection);
d->server->listen(fileName);
}
void QmlDebugConnection::newConnection()
{
Q_D(QmlDebugConnection);
delete d->device;
QLocalSocket *socket = d->server->nextPendingConnection();
d->server->close();
d->device = socket;
delete d->protocol;
d->protocol = new QPacketProtocol(socket, this);
QObject::connect(d->protocol, &QPacketProtocol::readyRead,
this, &QmlDebugConnection::protocolReadyRead);
connect(socket, &QLocalSocket::disconnected, this, &QmlDebugConnection::socketDisconnected);
connect(socket, static_cast<void (QLocalSocket::*)(QLocalSocket::LocalSocketError)>
(&QLocalSocket::error), this, [this](QLocalSocket::LocalSocketError error) {
socketError(static_cast<QAbstractSocket::SocketError>(error));
});
connect(socket, &QLocalSocket::stateChanged,
this, [this](QLocalSocket::LocalSocketState state) {
socketStateChanged(static_cast<QAbstractSocket::SocketState>(state));
});
socketConnected();
}
int QmlDebugConnection::currentDataStreamVersion() const
{
Q_D(const QmlDebugConnection);
......
......@@ -50,6 +50,7 @@ public:
~QmlDebugConnection();
void connectToHost(const QString &hostName, quint16 port);
void startLocalServer(const QString &fileName);
int currentDataStreamVersion() const;
void setMaximumDataStreamVersion(int maximumVersion);
......@@ -75,6 +76,7 @@ signals:
void socketStateChanged(QAbstractSocket::SocketState state);
private slots:
void newConnection();
void socketConnected();
void socketDisconnected();
void protocolReadyRead();
......
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