From 51b46e3bdedd82eed34844c372efe432ec51d95d Mon Sep 17 00:00:00 2001 From: Michael Marley Date: Sat, 20 Dec 2014 15:22:19 -0500 Subject: [PATCH] Fix potential state desync in disconnectFromIrc() Previously, disconnectFromIrc() would assume that if the socket was in any state other than ConnectedState that it was disconnected and send the socketDisconnected() signal. However, if the socket was in a different state, such as ConnectingState, this caused the corenetwork state and the socket state to become desynchronized. This patch causes disconnectFromIrc() to close the socket and start the socketCloseTimer in the event that the socket is in a state other than UnconnectedState or ConnectedState. --- src/core/corenetwork.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/core/corenetwork.cpp b/src/core/corenetwork.cpp index 4223c5f8..8655b110 100644 --- a/src/core/corenetwork.cpp +++ b/src/core/corenetwork.cpp @@ -232,17 +232,18 @@ void CoreNetwork::disconnectFromIrc(bool requested, const QString &reason, bool _quitReason = reason; displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Disconnecting. (%1)").arg((!requested && !withReconnect) ? tr("Core Shutdown") : _quitReason)); - switch (socket.state()) { - case QAbstractSocket::ConnectedState: - userInputHandler()->issueQuit(_quitReason); + if (socket.state() == QAbstractSocket::UnconnectedState) { + socketDisconnected(); + } else { + if (socket.state() == QAbstractSocket::ConnectedState) { + userInputHandler()->issueQuit(_quitReason); + } else { + socket.close(); + } if (requested || withReconnect) { // the irc server has 10 seconds to close the socket _socketCloseTimer.start(10000); - break; } - default: - socket.close(); - socketDisconnected(); } } -- 2.20.1