summaryrefslogtreecommitdiffstats
path: root/common/commands.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-07-03 14:02:27 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-07-03 14:02:27 +0200
commit55fe06979ceebe67553135b43aa47e70d931304b (patch)
tree16b10a744879cc1872d6c07624b59ae64469ddbf /common/commands.cpp
parent56fae95f49a1ca8ca614bd9f89b0ea5f872765e9 (diff)
parent288946f1694c2abe1d2c5800c87339d1e8780e4b (diff)
downloadsink-55fe06979ceebe67553135b43aa47e70d931304b.tar.gz
sink-55fe06979ceebe67553135b43aa47e70d931304b.zip
Merge branch 'develop'
Diffstat (limited to 'common/commands.cpp')
-rw-r--r--common/commands.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/common/commands.cpp b/common/commands.cpp
index eeb7f08..24f2017 100644
--- a/common/commands.cpp
+++ b/common/commands.cpp
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (C) 2014 Aaron Seigo <aseigo@kde.org> 2 * Copyright (C) 2014 Aaron Seigo <aseigo@kde.org>
3 * Copyright (C) 2016 Christian Mollekopf <mollekopf@kolabsys.com>
3 * 4 *
4 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public 6 * modify it under the terms of the GNU Lesser General Public
@@ -20,7 +21,7 @@
20 21
21#include "commands.h" 22#include "commands.h"
22 23
23#include <QIODevice> 24#include <QLocalSocket>
24#include <log.h> 25#include <log.h>
25 26
26namespace Sink { 27namespace Sink {
@@ -73,19 +74,19 @@ int headerSize()
73 return sizeof(int) + (sizeof(uint) * 2); 74 return sizeof(int) + (sizeof(uint) * 2);
74} 75}
75 76
76void write(QIODevice *device, int messageId, int commandId) 77void write(QLocalSocket *device, int messageId, int commandId)
77{ 78{
78 write(device, messageId, commandId, 0, 0); 79 write(device, messageId, commandId, 0, 0);
79} 80}
80 81
81static void write(QIODevice *device, const char *buffer, uint size) 82static void write(QLocalSocket *device, const char *buffer, uint size)
82{ 83{
83 if (device->write(buffer, size) < 0) { 84 if (device->write(buffer, size) < 0) {
84 SinkWarningCtx(Sink::Log::Context{"commands"}) << "Error while writing " << device->errorString(); 85 SinkWarningCtx(Sink::Log::Context{"commands"}) << "Error while writing " << device->errorString();
85 } 86 }
86} 87}
87 88
88void write(QIODevice *device, int messageId, int commandId, const char *buffer, uint size) 89void write(QLocalSocket *device, int messageId, int commandId, const char *buffer, uint size)
89{ 90{
90 if (size > 0 && !buffer) { 91 if (size > 0 && !buffer) {
91 size = 0; 92 size = 0;
@@ -97,15 +98,16 @@ void write(QIODevice *device, int messageId, int commandId, const char *buffer,
97 if (buffer) { 98 if (buffer) {
98 write(device, buffer, size); 99 write(device, buffer, size);
99 } 100 }
101 //The default implementation will happily buffer 200k bytes before sending it out which doesn't make the sytem exactly responsive.
102 //1k is arbitrary, but fits a bunch of messages at least.
103 if (device->bytesToWrite() > 1000) {
104 device->flush();
105 }
100} 106}
101 107
102void write(QIODevice *device, int messageId, int commandId, flatbuffers::FlatBufferBuilder &fbb) 108void write(QLocalSocket *device, int messageId, int commandId, flatbuffers::FlatBufferBuilder &fbb)
103{ 109{
104 const int dataSize = fbb.GetSize(); 110 write(device, messageId, commandId, (const char *)fbb.GetBufferPointer(), fbb.GetSize());
105 write(device, (const char *)&messageId, sizeof(int));
106 write(device, (const char *)&commandId, sizeof(int));
107 write(device, (const char *)&dataSize, sizeof(int));
108 write(device, (const char *)fbb.GetBufferPointer(), dataSize);
109} 111}
110 112
111} // namespace Commands 113} // namespace Commands