summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
64cf9f9)
Some socket errors (e.g. connection refused) don't trigger a disconnected()
from the socket, mostly because the socket hadn't been opened in the
first place.
To simplify the logic elsewhere, let's always send (exactly) one disconnected()
from the AuthHandler in case of socket errors. That way, we don't have to
introduce the mess we used to have in the reconnection logic in CoreConnection.
AuthHandler::AuthHandler(QObject *parent)
: QObject(parent),
_state(UnconnectedState),
AuthHandler::AuthHandler(QObject *parent)
: QObject(parent),
_state(UnconnectedState),
+ _socket(0),
+ _disconnectedSent(false)
{
_socket = socket;
connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), SIGNAL(socketStateChanged(QAbstractSocket::SocketState)));
{
_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());
{
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();
+ }
void setState(State state);
private slots:
void setState(State state);
private slots:
- void socketError(QAbstractSocket::SocketError error);
+ void onSocketError(QAbstractSocket::SocketError error);
+ void onSocketDisconnected();
private:
void invalidMessage();
State _state;
QTcpSocket *_socket; // FIXME: should be a QSharedPointer? -> premature disconnect before the peer has taken over
private:
void invalidMessage();
State _state;
QTcpSocket *_socket; // FIXME: should be a QSharedPointer? -> premature disconnect before the peer has taken over
+ bool _disconnectedSent;