From efa15f1d81f91b2a5fd2e35a9ecb1f5c17515b4b Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 26 Mar 2017 19:36:46 +0200 Subject: Test the result of the write operation. --- common/commands.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'common/commands.cpp') diff --git a/common/commands.cpp b/common/commands.cpp index ce83d03..eeb7f08 100644 --- a/common/commands.cpp +++ b/common/commands.cpp @@ -21,6 +21,7 @@ #include "commands.h" #include +#include namespace Sink { @@ -77,27 +78,34 @@ void write(QIODevice *device, int messageId, int commandId) write(device, messageId, commandId, 0, 0); } +static void write(QIODevice *device, const char *buffer, uint size) +{ + if (device->write(buffer, size) < 0) { + SinkWarningCtx(Sink::Log::Context{"commands"}) << "Error while writing " << device->errorString(); + } +} + void write(QIODevice *device, int messageId, int commandId, const char *buffer, uint size) { if (size > 0 && !buffer) { size = 0; } - device->write((const char *)&messageId, sizeof(int)); - device->write((const char *)&commandId, sizeof(int)); - device->write((const char *)&size, sizeof(uint)); + write(device, (const char *)&messageId, sizeof(int)); + write(device, (const char *)&commandId, sizeof(int)); + write(device, (const char *)&size, sizeof(uint)); if (buffer) { - device->write(buffer, size); + write(device, buffer, size); } } void write(QIODevice *device, int messageId, int commandId, flatbuffers::FlatBufferBuilder &fbb) { const int dataSize = fbb.GetSize(); - device->write((const char *)&messageId, sizeof(int)); - device->write((const char *)&commandId, sizeof(int)); - device->write((const char *)&dataSize, sizeof(int)); - device->write((const char *)fbb.GetBufferPointer(), dataSize); + write(device, (const char *)&messageId, sizeof(int)); + write(device, (const char *)&commandId, sizeof(int)); + write(device, (const char *)&dataSize, sizeof(int)); + write(device, (const char *)fbb.GetBufferPointer(), dataSize); } } // namespace Commands -- cgit v1.2.3