Skip to content

Commit

Permalink
sending the payload in chunks of a relatively small size in the hopes…
Browse files Browse the repository at this point in the history
… that it can help address issue eteran#253
  • Loading branch information
eteran authored and 1div0 committed Mar 24, 2021
1 parent d0ee742 commit 72933ea
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions client/nc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}

/**
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 72933ea

Please sign in to comment.