diff options
author | Nikolai Kosjar <nikolai.kosjar@theqtcompany.com> | 2015-05-29 13:14:32 +0200 |
---|---|---|
committer | Marco Bubke <marco.bubke@theqtcompany.com> | 2015-06-01 12:38:33 +0000 |
commit | c58de2bb4a5c4b4c808273282c72f81c065e609d (patch) | |
tree | dde171ee0d023e87b6dea894de21dc8941ab21fc | |
parent | 49f6c8def4fd0654af67c93c4a79b03f698ae773 (diff) | |
download | qt-creator-c58de2bb4a5c4b4c808273282c72f81c065e609d.tar.gz |
ConnectionClient: Fix unreliable sendEnd()
Calling QLocalSocket::flush() is not enough since it sends "as much as
possible from the internal write buffer" (doc), but not necessarily
everything.
Change-Id: Ica2220aaf9f8c01fe039c3b3b8e3ff7269c00851
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
-rw-r--r-- | src/libs/codemodelbackendipc/connectionclient.cpp | 12 | ||||
-rw-r--r-- | src/libs/codemodelbackendipc/connectionclient.h | 2 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/libs/codemodelbackendipc/connectionclient.cpp b/src/libs/codemodelbackendipc/connectionclient.cpp index 2bac59585a..61c12e4629 100644 --- a/src/libs/codemodelbackendipc/connectionclient.cpp +++ b/src/libs/codemodelbackendipc/connectionclient.cpp @@ -92,10 +92,22 @@ bool ConnectionClient::isConnected() const return localSocket.state() == QLocalSocket::ConnectedState; } +void ConnectionClient::waitUntilSocketIsFlushed() const +{ + // Avoid to call QAbstractSocket::waitForBytesWritten(), which is known to + // be unreliable on Windows. Instead, call processEvents() to actually send + // the data. + while (localSocket.bytesToWrite() > 0) { + QCoreApplication::processEvents(); + QThread::msleep(20); + } +} + void ConnectionClient::sendEndCommand() { serverProxy_.end(); localSocket.flush(); + waitUntilSocketIsFlushed(); } void ConnectionClient::resetProcessAliveTimer() diff --git a/src/libs/codemodelbackendipc/connectionclient.h b/src/libs/codemodelbackendipc/connectionclient.h index e118db7116..2e2cb2ef15 100644 --- a/src/libs/codemodelbackendipc/connectionclient.h +++ b/src/libs/codemodelbackendipc/connectionclient.h @@ -96,6 +96,8 @@ private: void disconnectProcessFinished() const; void connectStandardOutputAndError() const; + void waitUntilSocketIsFlushed() const; + private: mutable std::unique_ptr<QProcess> process_; QLocalSocket localSocket; |