X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fcommon%2Fauthhandler.cpp;h=792fcef131f85278a55e9024d7b50a9cb57cf33a;hb=47a6910aed00018c7230cc2cc90ae8e80fa77dda;hp=9877145e8795c6a6a955b90d666e03a3a0ea0357;hpb=64cf9f9b8a737dad5f29447805d4004cfd03c454;p=quassel.git diff --git a/src/common/authhandler.cpp b/src/common/authhandler.cpp index 9877145e..792fcef1 100644 --- a/src/common/authhandler.cpp +++ b/src/common/authhandler.cpp @@ -23,7 +23,8 @@ AuthHandler::AuthHandler(QObject *parent) : QObject(parent), _state(UnconnectedState), - _socket(0) + _socket(0), + _disconnectedSent(false) { } @@ -54,14 +55,32 @@ void AuthHandler::setSocket(QTcpSocket *socket) { _socket = socket; connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), SIGNAL(socketStateChanged(QAbstractSocket::SocketState))); - connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(socketError(QAbstractSocket::SocketError))); - connect(socket, SIGNAL(disconnected()), SIGNAL(disconnected())); + connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(onSocketError(QAbstractSocket::SocketError))); + connect(socket, SIGNAL(disconnected()), SLOT(onSocketDisconnected())); } -void AuthHandler::socketError(QAbstractSocket::SocketError error) +// Some errors (e.g. connection refused) don't trigger a disconnected() from the socket, so send this explicitly +// (but make sure it's only sent once!) +void AuthHandler::onSocketError(QAbstractSocket::SocketError error) { emit socketError(error, _socket->errorString()); + + if (!socket()->isOpen() || !socket()->isValid()) { + if (!_disconnectedSent) { + _disconnectedSent = true; + emit disconnected(); + } + } +} + + +void AuthHandler::onSocketDisconnected() +{ + if (!_disconnectedSent) { + _disconnectedSent = true; + emit disconnected(); + } }