summaryrefslogtreecommitdiffstats
path: root/common/resourceaccess.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-05-22 14:15:26 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-05-22 14:38:56 +0200
commitacd2902aaecaba864c5673adead98e59222e0fc9 (patch)
tree49b425a637e082f1259ed1678de3410d6146bc8c /common/resourceaccess.cpp
parentecf5bd3c4fd8557b06c6849b317d8d3ccaca528f (diff)
downloadsink-acd2902aaecaba864c5673adead98e59222e0fc9.tar.gz
sink-acd2902aaecaba864c5673adead98e59222e0fc9.zip
Propagate the synchronization error.
Diffstat (limited to 'common/resourceaccess.cpp')
-rw-r--r--common/resourceaccess.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp
index 991c930..b294221 100644
--- a/common/resourceaccess.cpp
+++ b/common/resourceaccess.cpp
@@ -96,7 +96,7 @@ public:
96 QVector<QSharedPointer<QueuedCommand>> commandQueue; 96 QVector<QSharedPointer<QueuedCommand>> commandQueue;
97 QMap<uint, QSharedPointer<QueuedCommand>> pendingCommands; 97 QMap<uint, QSharedPointer<QueuedCommand>> pendingCommands;
98 QMultiMap<uint, std::function<void(int error, const QString &errorMessage)>> resultHandler; 98 QMultiMap<uint, std::function<void(int error, const QString &errorMessage)>> resultHandler;
99 QSet<uint> completeCommands; 99 QHash<uint, bool> completeCommands;
100 uint messageId; 100 uint messageId;
101 bool openingSocket; 101 bool openingSocket;
102}; 102};
@@ -121,12 +121,17 @@ void ResourceAccess::Private::abortPendingOperations()
121 121
122void ResourceAccess::Private::callCallbacks() 122void ResourceAccess::Private::callCallbacks()
123{ 123{
124 for (auto id : completeCommands) { 124 for (auto id : completeCommands.keys()) {
125 const bool success = completeCommands.value(id);
125 // We remove the callbacks first because the handler can kill resourceaccess directly 126 // We remove the callbacks first because the handler can kill resourceaccess directly
126 const auto callbacks = resultHandler.values(id); 127 const auto callbacks = resultHandler.values(id);
127 resultHandler.remove(id); 128 resultHandler.remove(id);
128 for (auto handler : callbacks) { 129 for (auto handler : callbacks) {
129 handler(0, QString()); 130 if (success) {
131 handler(0, QString());
132 } else {
133 handler(1, "Command failed.");
134 }
130 } 135 }
131 } 136 }
132} 137}
@@ -536,7 +541,7 @@ bool ResourceAccess::processMessageBuffer()
536 auto buffer = Commands::GetCommandCompletion(d->partialMessageBuffer.constData() + headerSize); 541 auto buffer = Commands::GetCommandCompletion(d->partialMessageBuffer.constData() + headerSize);
537 Log() << QString("Command with messageId %1 completed %2").arg(buffer->id()).arg(buffer->success() ? "sucessfully" : "unsuccessfully"); 542 Log() << QString("Command with messageId %1 completed %2").arg(buffer->id()).arg(buffer->success() ? "sucessfully" : "unsuccessfully");
538 543
539 d->completeCommands << buffer->id(); 544 d->completeCommands.insert(buffer->id(), buffer->success());
540 // The callbacks can result in this object getting destroyed directly, so we need to ensure we finish our work first 545 // The callbacks can result in this object getting destroyed directly, so we need to ensure we finish our work first
541 queuedInvoke([=]() { d->callCallbacks(); }, this); 546 queuedInvoke([=]() { d->callCallbacks(); }, this);
542 break; 547 break;