Skip to content

Commit 1fca9c3

Browse files
QtSingleApplication: Bail out of read loop when peer disconnects
When messages are received while the event loop is inactive (for example, when locked by a native dialog), it can happen that a new connection is triggered which then goes into unconnected state when the peer terminates. Add a check to the loop and discard the connection in that case. Task-number: QTSOLBUG-193 Change-Id: I7d5502cb411d2b967bd06fe8734b97fee54b7d18 Reviewed-by: Joni Poikelin <[email protected]> Reviewed-by: Andy Shaw <[email protected]>
1 parent 5eac28c commit 1fca9c3

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

qtsingleapplication/src/qtlocalpeer.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,17 @@ void QtLocalPeer::receiveConnection()
176176
if (!socket)
177177
return;
178178

179-
while (socket->bytesAvailable() < (int)sizeof(quint32))
179+
while (true) {
180+
if (socket->state() == QAbstractSocket::UnconnectedState) {
181+
qWarning("QtLocalPeer: Peer disconnected");
182+
delete socket;
183+
return;
184+
}
185+
if (socket->bytesAvailable() >= qint64(sizeof(quint32)))
186+
break;
180187
socket->waitForReadyRead();
188+
}
189+
181190
QDataStream ds(socket);
182191
QByteArray uMsg;
183192
quint32 remaining;

0 commit comments

Comments
 (0)