diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-02-08 19:31:54 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-02-08 19:31:54 +0100 |
commit | d82f0f6e52b601c3067ca70183458f5ce9b22c22 (patch) | |
tree | 5b26b9a03ddc9758be6d8d9b3c5a8fa4ab6fd1b9 /common/resourceaccess.cpp | |
parent | be9f675ada44b04d3f74c68dc46cc7f7325ece0c (diff) | |
download | sink-d82f0f6e52b601c3067ca70183458f5ce9b22c22.tar.gz sink-d82f0f6e52b601c3067ca70183458f5ce9b22c22.zip |
Process a command in less than 0.1s
Diffstat (limited to 'common/resourceaccess.cpp')
-rw-r--r-- | common/resourceaccess.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp index daa2e82..80d60e8 100644 --- a/common/resourceaccess.cpp +++ b/common/resourceaccess.cpp | |||
@@ -41,6 +41,7 @@ | |||
41 | #include <QProcess> | 41 | #include <QProcess> |
42 | #include <QDataStream> | 42 | #include <QDataStream> |
43 | #include <QBuffer> | 43 | #include <QBuffer> |
44 | #include <QTime> | ||
44 | 45 | ||
45 | #undef Trace | 46 | #undef Trace |
46 | #define TracePrivate() Trace_area("client.communication." + resourceInstanceIdentifier) | 47 | #define TracePrivate() Trace_area("client.communication." + resourceInstanceIdentifier) |
@@ -170,23 +171,26 @@ KAsync::Job<void> ResourceAccess::Private::tryToConnect() | |||
170 | }, | 171 | }, |
171 | [this, counter](KAsync::Future<void> &future) { | 172 | [this, counter](KAsync::Future<void> &future) { |
172 | TracePrivate() << "Loop"; | 173 | TracePrivate() << "Loop"; |
173 | KAsync::wait(50) | 174 | connectToServer(resourceInstanceIdentifier) |
174 | .then(connectToServer(resourceInstanceIdentifier)) | ||
175 | .then<void, QSharedPointer<QLocalSocket> >([this, &future](const QSharedPointer<QLocalSocket> &s) { | 175 | .then<void, QSharedPointer<QLocalSocket> >([this, &future](const QSharedPointer<QLocalSocket> &s) { |
176 | Q_ASSERT(s); | 176 | Q_ASSERT(s); |
177 | socket = s; | 177 | socket = s; |
178 | future.setFinished(); | 178 | future.setFinished(); |
179 | }, | 179 | }, [&future, counter, this](int errorCode, const QString &errorString) { |
180 | [&future, counter, this](int errorCode, const QString &errorString) { | 180 | static int waitTime = 10; |
181 | const int maxRetries = 10; | 181 | static int timeout = 500; |
182 | static int maxRetries = timeout / waitTime; | ||
182 | if (*counter > maxRetries) { | 183 | if (*counter > maxRetries) { |
183 | TracePrivate() << "Giving up"; | 184 | TracePrivate() << "Giving up"; |
184 | future.setError(-1, "Failed to connect to socket"); | 185 | future.setError(-1, "Failed to connect to socket"); |
185 | } else { | 186 | } else { |
186 | future.setFinished(); | 187 | KAsync::wait(waitTime).then<void>([&future]() { |
188 | future.setFinished(); | ||
189 | }).exec(); | ||
187 | } | 190 | } |
188 | *counter = *counter + 1; | 191 | *counter = *counter + 1; |
189 | }).exec(); | 192 | }) |
193 | .exec(); | ||
190 | }); | 194 | }); |
191 | } | 195 | } |
192 | 196 | ||