summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2017-10-09 11:55:19 +0200
committerEike Ziller <eike.ziller@qt.io>2017-10-09 11:55:19 +0200
commitafef032a483895eb24348d076a8e1e55d36286eb (patch)
tree70dc4b9ae5752fc9b6f69fdd62badd56c5f1546d
parent5e0f2b926255a17bc07487126ce4d769c7b1a81b (diff)
parent2ce53ba9f0f03ac024ac206fc521dcc9d4cfe456 (diff)
Merge remote-tracking branch 'origin/4.5'
-rw-r--r--app/main.cpp31
1 files changed, 23 insertions, 8 deletions
diff --git a/app/main.cpp b/app/main.cpp
index 0de996d..26e4183 100644
--- a/app/main.cpp
+++ b/app/main.cpp
@@ -35,6 +35,7 @@
#include <QScopedPointer>
#include <QAbstractSocket>
#include <QTcpSocket>
+#include <QTimer>
#include <limits>
#ifdef Q_OS_WIN
@@ -56,21 +57,25 @@ enum ErrorCodes {
class PerfTcpSocket : public QTcpSocket {
Q_OBJECT
public:
- PerfTcpSocket(QCoreApplication *app);
+ PerfTcpSocket(QCoreApplication *app, const QString &host, quint16 port);
+ void tryConnect();
public slots:
void readingFinished();
void processError(QAbstractSocket::SocketError error);
private:
- bool reading;
+ QString host;
+ quint16 port = 0;
+ quint16 tries = 0;
+ bool reading = true;
};
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
app.setApplicationName(QLatin1String("perfparser"));
- app.setApplicationVersion(QLatin1String("4.3"));
+ app.setApplicationVersion(QLatin1String("4.5"));
QCommandLineParser parser;
parser.setApplicationDescription(QLatin1String("Perf data parser and unwinder."));
@@ -200,7 +205,8 @@ int main(int argc, char *argv[])
QScopedPointer<QIODevice> infile;
if (parser.isSet(host)) {
- PerfTcpSocket *socket = new PerfTcpSocket(&app);
+ PerfTcpSocket *socket = new PerfTcpSocket(&app, parser.value(host),
+ parser.value(port).toUShort());
infile.reset(socket);
} else {
if (parser.isSet(input))
@@ -303,8 +309,7 @@ int main(int argc, char *argv[])
PerfTcpSocket *socket = static_cast<PerfTcpSocket *>(infile.data());
QObject::connect(socket, &QTcpSocket::disconnected, &data, &PerfData::finishReading);
QObject::connect(&data, &PerfData::finished, socket, &PerfTcpSocket::readingFinished);
- socket->connectToHost(parser.value(host), parser.value(port).toUShort(),
- QIODevice::ReadOnly);
+ socket->tryConnect();
} else {
if (!infile->open(QIODevice::ReadOnly))
return CannotOpen;
@@ -319,17 +324,27 @@ void PerfTcpSocket::processError(QAbstractSocket::SocketError error)
{
if (reading) {
qWarning() << "socket error" << error << errorString();
- qApp->exit(TcpSocketError);
+ if (tries > 10)
+ qApp->exit(TcpSocketError);
+ else
+ QTimer::singleShot(1 << tries, this, &PerfTcpSocket::tryConnect);
} // Otherwise ignore the error. We don't need the socket anymore
}
-PerfTcpSocket::PerfTcpSocket(QCoreApplication *app) : QTcpSocket(app), reading(true)
+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)));
}
+void PerfTcpSocket::tryConnect()
+{
+ ++tries;
+ connectToHost(host, port, QIODevice::ReadOnly);
+}
+
void PerfTcpSocket::readingFinished()
{
reading = false;