diff options
Diffstat (limited to 'common/resourceaccess.cpp')
-rw-r--r-- | common/resourceaccess.cpp | 23 |
1 files changed, 19 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() | |||
209 | void ResourceAccess::connected() | 212 | void 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 | ||
252 | void ResourceAccess::connectionError(QLocalSocket::LocalSocketError error) | 255 | void 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 | |||
283 | void 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())) { |