X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcommon%2Fremotepeer.cpp;h=e8b682d7e060020f5fa5870d24ed3b974ac90ccf;hb=2dca302472ee44923e164784191891711eff626a;hp=fba57cd3e0c18c9d1fb1173e40ca4ce2d7f112dc;hpb=9d54503555534a2c554f09a33df6afa33d6308ec;p=quassel.git diff --git a/src/common/remotepeer.cpp b/src/common/remotepeer.cpp index fba57cd3..e8b682d7 100644 --- a/src/common/remotepeer.cpp +++ b/src/common/remotepeer.cpp @@ -40,9 +40,10 @@ RemotePeer::RemotePeer(::AuthHandler *authHandler, QTcpSocket *socket, QObject * _lag(0) { socket->setParent(this); - connect(socket, SIGNAL(disconnected()), SIGNAL(disconnected())); - connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), SIGNAL(socketStateChanged(QAbstractSocket::SocketState))); + connect(socket, SIGNAL(readyRead()), SLOT(onSocketDataAvailable())); + connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), SLOT(onSocketStateChanged(QAbstractSocket::SocketState))); connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(onSocketError(QAbstractSocket::SocketError))); + connect(socket, SIGNAL(disconnected()), SIGNAL(disconnected())); #ifdef HAVE_SSL QSslSocket *sslSocket = qobject_cast(socket); @@ -51,6 +52,19 @@ RemotePeer::RemotePeer(::AuthHandler *authHandler, QTcpSocket *socket, QObject * #endif connect(_heartBeatTimer, SIGNAL(timeout()), SLOT(sendHeartBeat())); + + // It's possible that more data has already arrived during the handshake, so readyRead() wouldn't be triggered. + // However, we can't call a virtual function from the ctor, so let's do it asynchronously. + if (socket->bytesAvailable()) + QTimer::singleShot(0, this, SLOT(onSocketDataAvailable())); +} + + +void RemotePeer::onSocketStateChanged(QAbstractSocket::SocketState state) +{ + if (state == QAbstractSocket::ClosingState) { + emit statusMessage(tr("Disconnecting...")); + } } @@ -175,7 +189,7 @@ void RemotePeer::handle(const HeartBeat &heartBeat) void RemotePeer::handle(const HeartBeatReply &heartBeatReply) { _heartBeatCount = 0; -#if QT_VERSION >= 0x040900 +#if QT_VERSION >= 0x040700 emit lagUpdated(heartBeatReply.timestamp.msecsTo(QDateTime::currentDateTime().toUTC()) / 2); #else emit lagUpdated(heartBeatReply.timestamp.time().msecsTo(QDateTime::currentDateTime().toUTC().time()) / 2);