summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-03-29 11:22:24 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-03-31 11:11:08 +0200
commit34851314d39307f22df01a4b711e6fd3c5618e23 (patch)
treedb1b6d191f40544eadc302dd33af8561e1d5c0c1
parent0b2c8bb61ad1c8fdc4e471172f49b704ca3a1ccb (diff)
downloadsink-34851314d39307f22df01a4b711e6fd3c5618e23.tar.gz
sink-34851314d39307f22df01a4b711e6fd3c5618e23.zip
Don't try to restart the resource on every disconnect.
There's a chance that the resource actually wanted to shut-down. Instead ResourceAccess should only reopen the connection if it still has work to do.
-rw-r--r--common/resourceaccess.cpp23
-rw-r--r--common/resourceaccess.h1
2 files changed, 20 insertions, 4 deletions
diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp
index 20e1e8c..22d7d97 100644
--- a/common/resourceaccess.cpp
+++ b/common/resourceaccess.cpp
@@ -79,6 +79,7 @@ public:
79 QLocalSocket *socket; 79 QLocalSocket *socket;
80 QTimer *tryOpenTimer; 80 QTimer *tryOpenTimer;
81 bool startingProcess; 81 bool startingProcess;
82 bool openingConnection;
82 QByteArray partialMessageBuffer; 83 QByteArray partialMessageBuffer;
83 flatbuffers::FlatBufferBuilder fbb; 84 flatbuffers::FlatBufferBuilder fbb;
84 QVector<QueuedCommand *> commandQueue; 85 QVector<QueuedCommand *> commandQueue;
@@ -91,6 +92,7 @@ ResourceAccess::Private::Private(const QString &name, ResourceAccess *q)
91 socket(new QLocalSocket(q)), 92 socket(new QLocalSocket(q)),
92 tryOpenTimer(new QTimer(q)), 93 tryOpenTimer(new QTimer(q)),
93 startingProcess(false), 94 startingProcess(false),
95 openingConnection(false),
94 messageId(0) 96 messageId(0)
95{ 97{
96} 98}
@@ -191,6 +193,7 @@ void ResourceAccess::open()
191 log("Socket valid, so not opening again"); 193 log("Socket valid, so not opening again");
192 return; 194 return;
193 } 195 }
196 d->openingConnection = true;
194 197
195 //TODO: if we try and try and the process does not pick up 198 //TODO: if we try and try and the process does not pick up
196 // we should probably try to start the process again 199 // we should probably try to start the process again
@@ -209,6 +212,7 @@ void ResourceAccess::close()
209void ResourceAccess::connected() 212void ResourceAccess::connected()
210{ 213{
211 d->startingProcess = false; 214 d->startingProcess = false;
215 d->openingConnection = false;
212 216
213 if (!isReady()) { 217 if (!isReady()) {
214 return; 218 return;
@@ -246,7 +250,6 @@ void ResourceAccess::disconnected()
246 d->socket->close(); 250 d->socket->close();
247 log(QString("Disconnected from %1").arg(d->socket->fullServerName())); 251 log(QString("Disconnected from %1").arg(d->socket->fullServerName()));
248 emit ready(false); 252 emit ready(false);
249 open();
250} 253}
251 254
252void ResourceAccess::connectionError(QLocalSocket::LocalSocketError error) 255void ResourceAccess::connectionError(QLocalSocket::LocalSocketError error)
@@ -257,18 +260,30 @@ void ResourceAccess::connectionError(QLocalSocket::LocalSocketError error)
257 } 260 }
258 return; 261 return;
259 } 262 }
260 log(QString("Connection error: %1 : %2").arg(error).arg(d->socket->errorString())); 263
261 if (error == QLocalSocket::PeerClosedError) { 264 if (error == QLocalSocket::PeerClosedError) {
262 log("The resource closed the connection. It probably crashed."); 265 Log() << "The resource closed the connection.";
266 } else {
267 Warning() << QString("Connection error: %1 : %2").arg(error).arg(d->socket->errorString());
263 } 268 }
264 269
270 //TODO We could first try to reconnect and resend the message if necessary.
265 for(auto handler : d->resultHandler.values()) { 271 for(auto handler : d->resultHandler.values()) {
266 handler(1, "The resource closed unexpectedly"); 272 handler(1, "The resource closed unexpectedly");
267 } 273 }
268 d->resultHandler.clear(); 274 d->resultHandler.clear();
269 275
276 //We're trying to connect but failed, start the resource and retry.
277 //Don't automatically restart on later disconnects.
278 if (d->openingConnection) {
279 startResourceAndConnect();
280 }
281}
282
283void ResourceAccess::startResourceAndConnect()
284{
270 d->startingProcess = true; 285 d->startingProcess = true;
271 log(QString("Attempting to start resource ") + d->resourceName); 286 Log() << "Attempting to start resource " + d->resourceName;
272 QStringList args; 287 QStringList args;
273 args << d->resourceName; 288 args << d->resourceName;
274 if (QProcess::startDetached("akonadi2_synchronizer", args, QDir::homePath())) { 289 if (QProcess::startDetached("akonadi2_synchronizer", args, QDir::homePath())) {
diff --git a/common/resourceaccess.h b/common/resourceaccess.h
index c5b8a6c..a5a2547 100644
--- a/common/resourceaccess.h
+++ b/common/resourceaccess.h
@@ -66,6 +66,7 @@ private Q_SLOTS:
66private: 66private:
67 void log(const QString &message); 67 void log(const QString &message);
68 void registerCallback(uint messageId, const std::function<void(int error, const QString &)> &callback); 68 void registerCallback(uint messageId, const std::function<void(int error, const QString &)> &callback);
69 void startResourceAndConnect();
69 70
70 class Private; 71 class Private;
71 Private * const d; 72 Private * const d;