diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2019-10-31 09:06:09 -0400 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2019-10-31 09:06:09 -0400 |
| commit | a523a0b21b66f4114598a340ea7346d24d6ea0e5 (patch) | |
| tree | 1c9c4cc54215bc98326918efc885b834a1167790 /src/singleinstance.cpp | |
| parent | 6c881c8502cc6707b56676e767057dd4bda8d363 (diff) | |
make sure all the data is sent before disconnecting
don't fail if waitForReadyRead() returns false but there's data available
Diffstat (limited to 'src/singleinstance.cpp')
| -rw-r--r-- | src/singleinstance.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/singleinstance.cpp b/src/singleinstance.cpp index 7abf3879..aa62d40a 100644 --- a/src/singleinstance.cpp +++ b/src/singleinstance.cpp @@ -20,6 +20,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include "singleinstance.h"
#include "utility.h"
#include <report.h>
+#include <log.h>
#include <QLocalSocket>
static const char s_Key[] = "mo-43d1a3ad-eeb0-4818-97c9-eda5216c29b5";
@@ -93,17 +94,33 @@ void SingleInstance::sendMessage(const QString &message) }
socket.disconnectFromServer();
+ socket.waitForDisconnected();
}
void SingleInstance::receiveMessage()
{
QLocalSocket *socket = m_Server.nextPendingConnection();
- if (!socket->waitForReadyRead(s_Timeout)) {
- reportError(tr("failed to receive data from secondary instance: %1").arg(socket->errorString()));
+ if (!socket) {
return;
}
+ if (!socket->waitForReadyRead(s_Timeout)) {
+ // check if there are bytes available; if so, it probably means the data was
+ // already received by the time waitForReadyRead() was called and the
+ // connection has been closed
+ const auto av = socket->bytesAvailable();
+
+ if (av <= 0) {
+ MOBase::log::error(
+ "failed to receive data from secondary instance: {}",
+ socket->errorString());
+
+ reportError(tr("failed to receive data from secondary instance: %1").arg(socket->errorString()));
+ return;
+ }
+ }
+
QString message = QString::fromUtf8(socket->readAll().constData());
emit messageSent(message);
socket->disconnectFromServer();
|
