summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2018-04-20 13:19:53 +0200
committerUlf Hermann <ulf.hermann@qt.io>2018-04-20 13:16:45 +0000
commit88d5bd3ea36fbf810c1f49b767be435f123759bf (patch)
tree9a90a1dc2cc167132a9092b3563356b2b5feb869
parent418734b9f4baaaadd289b6379701912e864330da (diff)
Exit gracefully when the remote end closes the connection
This is generally not an error. Unfortunately QTcpSocket doesn't issue a close() when it's disconnected, so PerfData doesn't notice. We can manually trigger this, though. Change-Id: I37bf2a54fc102c8f7c0a26a760de1c8a6cf6d526 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r--app/main.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/app/main.cpp b/app/main.cpp
index c5d6039..68d8f6b 100644
--- a/app/main.cpp
+++ b/app/main.cpp
@@ -390,19 +390,22 @@ int main(int argc, char *argv[])
void PerfTcpSocket::processError(QAbstractSocket::SocketError error)
{
+ if (error == QAbstractSocket::RemoteHostClosedError)
+ return;
+
qWarning() << "socket error" << error << errorString();
- if (tries > 10)
+ if (state() == QAbstractSocket::ConnectedState || tries > 10)
qApp->exit(TcpSocketError);
else
QTimer::singleShot(1 << tries, this, &PerfTcpSocket::tryConnect);
}
-
PerfTcpSocket::PerfTcpSocket(QCoreApplication *app, const QString &host, quint16 port) :
QTcpSocket(app), host(host), port(port)
{
- connect(this, SIGNAL(error(QAbstractSocket::SocketError)),
- this, SLOT(processError(QAbstractSocket::SocketError)));
+ connect(this, QOverload<QAbstractSocket::SocketError>::of(&QTcpSocket::error),
+ this, &PerfTcpSocket::processError);
+ connect(this, &QAbstractSocket::disconnected, this, &QIODevice::close);
}
void PerfTcpSocket::tryConnect()