diff options
Diffstat (limited to 'common/resourceaccess.cpp')
-rw-r--r-- | common/resourceaccess.cpp | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp index 8988032..7be1259 100644 --- a/common/resourceaccess.cpp +++ b/common/resourceaccess.cpp | |||
@@ -368,6 +368,8 @@ void ResourceAccess::open() | |||
368 | void ResourceAccess::close() | 368 | void ResourceAccess::close() |
369 | { | 369 | { |
370 | log(QString("Closing %1").arg(d->socket->fullServerName())); | 370 | log(QString("Closing %1").arg(d->socket->fullServerName())); |
371 | Trace() << "Pending commands: " << d->pendingCommands.size(); | ||
372 | Trace() << "Queued commands: " << d->commandQueue.size(); | ||
371 | d->socket->close(); | 373 | d->socket->close(); |
372 | } | 374 | } |
373 | 375 | ||
@@ -393,12 +395,24 @@ void ResourceAccess::processCommandQueue() | |||
393 | { | 395 | { |
394 | //TODO: serialize instead of blast them all through the socket? | 396 | //TODO: serialize instead of blast them all through the socket? |
395 | Trace() << "We have " << d->commandQueue.size() << " queued commands"; | 397 | Trace() << "We have " << d->commandQueue.size() << " queued commands"; |
398 | Trace() << "Pending commands: " << d->pendingCommands.size(); | ||
396 | for (auto command: d->commandQueue) { | 399 | for (auto command: d->commandQueue) { |
397 | sendCommand(command); | 400 | sendCommand(command); |
398 | } | 401 | } |
399 | d->commandQueue.clear(); | 402 | d->commandQueue.clear(); |
400 | } | 403 | } |
401 | 404 | ||
405 | void ResourceAccess::processPendingCommandQueue() | ||
406 | { | ||
407 | Trace() << "We have " << d->pendingCommands.size() << " pending commands"; | ||
408 | for (auto command: d->pendingCommands) { | ||
409 | Trace() << "Reenquing command " << command->commandId; | ||
410 | d->commandQueue << command; | ||
411 | } | ||
412 | d->pendingCommands.clear(); | ||
413 | processCommandQueue(); | ||
414 | } | ||
415 | |||
402 | void ResourceAccess::connected() | 416 | void ResourceAccess::connected() |
403 | { | 417 | { |
404 | if (!isReady()) { | 418 | if (!isReady()) { |
@@ -415,6 +429,9 @@ void ResourceAccess::connected() | |||
415 | Commands::write(d->socket.data(), ++d->messageId, Commands::HandshakeCommand, fbb); | 429 | Commands::write(d->socket.data(), ++d->messageId, Commands::HandshakeCommand, fbb); |
416 | } | 430 | } |
417 | 431 | ||
432 | //Reenqueue pending commands, we failed to send them | ||
433 | processPendingCommandQueue(); | ||
434 | //Send queued commands | ||
418 | processCommandQueue(); | 435 | processCommandQueue(); |
419 | 436 | ||
420 | emit ready(true); | 437 | emit ready(true); |
@@ -424,8 +441,6 @@ void ResourceAccess::disconnected() | |||
424 | { | 441 | { |
425 | log(QString("Disconnected from %1").arg(d->socket->fullServerName())); | 442 | log(QString("Disconnected from %1").arg(d->socket->fullServerName())); |
426 | d->socket->close(); | 443 | d->socket->close(); |
427 | //TODO fail all existing jobs? or retry | ||
428 | d->abortPendingOperations(); | ||
429 | emit ready(false); | 444 | emit ready(false); |
430 | } | 445 | } |
431 | 446 | ||
@@ -433,12 +448,14 @@ void ResourceAccess::connectionError(QLocalSocket::LocalSocketError error) | |||
433 | { | 448 | { |
434 | if (error == QLocalSocket::PeerClosedError) { | 449 | if (error == QLocalSocket::PeerClosedError) { |
435 | Log(d->resourceInstanceIdentifier) << "The resource closed the connection."; | 450 | Log(d->resourceInstanceIdentifier) << "The resource closed the connection."; |
451 | d->abortPendingOperations(); | ||
436 | } else { | 452 | } else { |
437 | Warning() << QString("Connection error: %1 : %2").arg(error).arg(d->socket->errorString()); | 453 | Warning() << QString("Connection error: %1 : %2").arg(error).arg(d->socket->errorString()); |
454 | if (d->pendingCommands.size()) { | ||
455 | Trace() << "Reconnecting due to pending operations: " << d->pendingCommands.size(); | ||
456 | open(); | ||
457 | } | ||
438 | } | 458 | } |
439 | |||
440 | //TODO We could first try to reconnect and resend the message if necessary. | ||
441 | d->abortPendingOperations(); | ||
442 | } | 459 | } |
443 | 460 | ||
444 | void ResourceAccess::readResourceMessage() | 461 | void ResourceAccess::readResourceMessage() |