diff options
Diffstat (limited to 'synchronizer/listener.cpp')
-rw-r--r-- | synchronizer/listener.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/synchronizer/listener.cpp b/synchronizer/listener.cpp index 1553f7d..2559664 100644 --- a/synchronizer/listener.cpp +++ b/synchronizer/listener.cpp | |||
@@ -203,13 +203,13 @@ void Listener::processClientBuffers() | |||
203 | } | 203 | } |
204 | } | 204 | } |
205 | 205 | ||
206 | void Listener::processCommand(int commandId, uint messageId, Client &client, uint size, const std::function<void()> &callback) | 206 | void Listener::processCommand(int commandId, uint messageId, const QByteArray &commandBuffer, Client &client, const std::function<void()> &callback) |
207 | { | 207 | { |
208 | switch (commandId) { | 208 | switch (commandId) { |
209 | case Akonadi2::Commands::HandshakeCommand: { | 209 | case Akonadi2::Commands::HandshakeCommand: { |
210 | flatbuffers::Verifier verifier((const uint8_t *)client.commandBuffer.constData(), size); | 210 | flatbuffers::Verifier verifier((const uint8_t *)commandBuffer.constData(), commandBuffer.size()); |
211 | if (Akonadi2::VerifyHandshakeBuffer(verifier)) { | 211 | if (Akonadi2::VerifyHandshakeBuffer(verifier)) { |
212 | auto buffer = Akonadi2::GetHandshake(client.commandBuffer.constData()); | 212 | auto buffer = Akonadi2::GetHandshake(commandBuffer.constData()); |
213 | client.name = buffer->name()->c_str(); | 213 | client.name = buffer->name()->c_str(); |
214 | sendCurrentRevision(client); | 214 | sendCurrentRevision(client); |
215 | } else { | 215 | } else { |
@@ -218,9 +218,9 @@ void Listener::processCommand(int commandId, uint messageId, Client &client, uin | |||
218 | break; | 218 | break; |
219 | } | 219 | } |
220 | case Akonadi2::Commands::SynchronizeCommand: { | 220 | case Akonadi2::Commands::SynchronizeCommand: { |
221 | flatbuffers::Verifier verifier((const uint8_t *)client.commandBuffer.constData(), size); | 221 | flatbuffers::Verifier verifier((const uint8_t *)commandBuffer.constData(), commandBuffer.size()); |
222 | if (Akonadi2::VerifySynchronizeBuffer(verifier)) { | 222 | if (Akonadi2::VerifySynchronizeBuffer(verifier)) { |
223 | auto buffer = Akonadi2::GetSynchronize(client.commandBuffer.constData()); | 223 | auto buffer = Akonadi2::GetSynchronize(commandBuffer.constData()); |
224 | Log() << QString("\tSynchronize request (id %1) from %2").arg(messageId).arg(client.name); | 224 | Log() << QString("\tSynchronize request (id %1) from %2").arg(messageId).arg(client.name); |
225 | loadResource(); | 225 | loadResource(); |
226 | if (!m_resource) { | 226 | if (!m_resource) { |
@@ -250,7 +250,7 @@ void Listener::processCommand(int commandId, uint messageId, Client &client, uin | |||
250 | Log() << "\tCommand id " << messageId << " of type \"" << Akonadi2::Commands::name(commandId) << "\" from " << client.name; | 250 | Log() << "\tCommand id " << messageId << " of type \"" << Akonadi2::Commands::name(commandId) << "\" from " << client.name; |
251 | loadResource(); | 251 | loadResource(); |
252 | if (m_resource) { | 252 | if (m_resource) { |
253 | m_resource->processCommand(commandId, client.commandBuffer, size, m_pipeline); | 253 | m_resource->processCommand(commandId, commandBuffer, m_pipeline); |
254 | } | 254 | } |
255 | break; | 255 | break; |
256 | case Akonadi2::Commands::ShutdownCommand: | 256 | case Akonadi2::Commands::ShutdownCommand: |
@@ -262,7 +262,7 @@ void Listener::processCommand(int commandId, uint messageId, Client &client, uin | |||
262 | Log() << QString("\tReceived custom command from %1: ").arg(client.name) << commandId; | 262 | Log() << QString("\tReceived custom command from %1: ").arg(client.name) << commandId; |
263 | loadResource(); | 263 | loadResource(); |
264 | if (m_resource) { | 264 | if (m_resource) { |
265 | m_resource->processCommand(commandId, client.commandBuffer, size, m_pipeline); | 265 | m_resource->processCommand(commandId, commandBuffer, m_pipeline); |
266 | } | 266 | } |
267 | } else { | 267 | } else { |
268 | Warning() << QString("\tReceived invalid command from %1: ").arg(client.name) << commandId; | 268 | Warning() << QString("\tReceived invalid command from %1: ").arg(client.name) << commandId; |
@@ -307,7 +307,9 @@ bool Listener::processClientBuffer(Client &client) | |||
307 | 307 | ||
308 | auto socket = QPointer<QLocalSocket>(client.socket); | 308 | auto socket = QPointer<QLocalSocket>(client.socket); |
309 | auto clientName = client.name; | 309 | auto clientName = client.name; |
310 | processCommand(commandId, messageId, client, size, [this, messageId, commandId, socket, clientName]() { | 310 | const QByteArray commandBuffer = client.commandBuffer.left(size); |
311 | client.commandBuffer.remove(0, size); | ||
312 | processCommand(commandId, messageId, commandBuffer, client, [this, messageId, commandId, socket, clientName]() { | ||
311 | Log() << QString("\tCompleted command messageid %1 of type \"%2\" from %3").arg(messageId).arg(QString(Akonadi2::Commands::name(commandId))).arg(clientName); | 313 | Log() << QString("\tCompleted command messageid %1 of type \"%2\" from %3").arg(messageId).arg(QString(Akonadi2::Commands::name(commandId))).arg(clientName); |
312 | if (socket) { | 314 | if (socket) { |
313 | sendCommandCompleted(socket.data(), messageId); | 315 | sendCommandCompleted(socket.data(), messageId); |
@@ -315,7 +317,6 @@ bool Listener::processClientBuffer(Client &client) | |||
315 | Log() << QString("Socket became invalid before we could send a response. client: %1").arg(clientName); | 317 | Log() << QString("Socket became invalid before we could send a response. client: %1").arg(clientName); |
316 | } | 318 | } |
317 | }); | 319 | }); |
318 | client.commandBuffer.remove(0, size); | ||
319 | 320 | ||
320 | return client.commandBuffer.size() >= headerSize; | 321 | return client.commandBuffer.size() >= headerSize; |
321 | } | 322 | } |