From 72933ea75f3a38ae50048354c86bb0d517492c30 Mon Sep 17 00:00:00 2001 From: Evan Teran Date: Thu, 7 Jan 2021 16:21:52 -0500 Subject: [PATCH] sending the payload in chunks of a relatively small size in the hopes that it can help address issue #253 --- client/nc.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/client/nc.cpp b/client/nc.cpp index cc6aadad5..e39980983 100644 --- a/client/nc.cpp +++ b/client/nc.cpp @@ -401,6 +401,26 @@ int startServer(const char *message, const QStringList &commandLineArgs) { } } +bool writeToSocket(QLocalSocket *socket, const QByteArray &data) { + int remaining = data.size(); + const char *ptr = data.data(); + + constexpr int MaxChunk = 4096; + + while (socket->isOpen() && remaining > 0) { + const int64_t written = socket->write(ptr, std::min(MaxChunk, remaining)); + if (written == -1) { + return false; + } + + socket->waitForBytesWritten(-1); + + ptr += written; + remaining -= written; + } + return true; +} + } /** @@ -480,9 +500,7 @@ int main(int argc, char *argv[]) { stream.setVersion(QDataStream::Qt_5_0); stream << commandLine.jsonRequest; - socket->write(ba); - socket->flush(); - socket->waitForBytesWritten(timeout.count()); + writeToSocket(socket.get(), ba); // if we are enabling wait mode, we simply wait for the server // to close the socket. We'll leave it to the server to track