Encapsulate socket state in AuthHandler, properly handle disconnects
authorManuel Nickschas <sputnick@quassel-irc.org>
Sat, 18 Jan 2014 18:06:06 +0000 (19:06 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sat, 18 Jan 2014 18:06:06 +0000 (19:06 +0100)
commitb654b2f908590b6f69a7edadf9dacf1277a4493b
tree7b6897e5f9491eac4c1dc4e95ec94773e03401bc
parent7920d1f52f65421496fa2ed41c2da8e3244b267b
Encapsulate socket state in AuthHandler, properly handle disconnects

The actual state of the socket used to connect to the core should be
kept internal to AuthHandler (and RemotePeer), in particular because
we want to handle the detection of legacy cores transparently later.
Also, it does not make sense to handle individual socket states outside
of the classes actually dealing with the socket; handling errors and
disconnection is sufficient. Both AuthHandler and Peer now emit
statusMessage() signals for displaying the socket state in the UI.
Because it was never used nor is it needed, this commits also removes
the AuthHandler::State enum.

While doing this, I also stumbled over the most likely reason for the
problem that the client would sometimes not reconnect to a core even
though it would claim to be disconnected:

QTcpSocket will only emit disconnected() when it had already reached
the Connected state, i.e. not if it was still connecting. While
CoreConnection would detect the socket go back to UnconnectedState,
and set its own state to Disconnected, it would never do its internal
clean-up which was tied to the socket's disconnected() signal, unless
the socket would also emit an error (which it apparently doesn't do
in all cases...). As a result, reconnecting was not possible in these
situations.

With these changes, CoreConnection relies solely on AuthHandler's
disconnected() signal, which is properly emitted even if establishing
the connection fails.
src/client/clientauthhandler.cpp
src/client/clientauthhandler.h
src/client/coreconnection.cpp
src/client/coreconnection.h
src/common/authhandler.cpp
src/common/authhandler.h
src/common/remotepeer.cpp
src/common/remotepeer.h