summaryrefslogtreecommitdiff
path: root/src/singleinstance.cpp
diff options
context:
space:
mode:
authorChris Bessent <lost.dragonist@gmail.com>2020-01-06 05:17:01 -0700
committerGitHub <noreply@github.com>2020-01-06 05:17:01 -0700
commitdfa600996c49c1b23dca884c963dc917bd9cfc0a (patch)
treec6def4277cc962822d0dcde71fa9148e050f693f /src/singleinstance.cpp
parente69078e2399a88bda7bb9ffae7a3d57db9a4e9cf (diff)
parentd1a788dfad341b32235abc25c2ba1645f8be1ace (diff)
Merge pull request #954 from ModOrganizer2/Develop
Stage for release 2.2.2
Diffstat (limited to 'src/singleinstance.cpp')
-rw-r--r--src/singleinstance.cpp21
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();