From 4c4aec75c42dc212b6725cf1cb42ab61fb09e8fd Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Wed, 13 Nov 2013 00:37:12 +0100 Subject: [PATCH] Fix flushing of sockets, causing random sync errors TIL that flushing a socket may trigger a readyRead(). In certain cases this would lead to compression being enabled on the client side too late (because we would flush the socket before), breaking the sync to core. As (contrary to starting SSL) enabling the compression does not care if there's still uncompressed data in the socket's write buffer, we can just remove this flush. Also, let's make it explicit that we flush immediately before starting encryption, rather than hiding that somewhere in the LegacyPeer, to avoid introducing weird bugs later. And also flush the socket before handing the peer over to the CoreSession, as we used to do before the refactoring - we don't want bug #682 back. --- src/common/protocols/legacy/legacypeer.cpp | 2 -- src/core/coreauthhandler.cpp | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/protocols/legacy/legacypeer.cpp b/src/common/protocols/legacy/legacypeer.cpp index 08f5b15c..eab7ea95 100644 --- a/src/common/protocols/legacy/legacypeer.cpp +++ b/src/common/protocols/legacy/legacypeer.cpp @@ -48,7 +48,6 @@ void LegacyPeer::setSignalProxy(::SignalProxy *proxy) RemotePeer::setSignalProxy(proxy); // FIXME only in compat mode - socket()->flush(); if (proxy) { // enable compression now if requested - the initial handshake is uncompressed in the legacy protocol! _useCompression = socket()->property("UseCompression").toBool(); @@ -302,7 +301,6 @@ void LegacyPeer::dispatch(const ClientRegistered &msg) { m["LoginEnabled"] = m["Configured"] = msg.coreConfigured; writeSocketData(m); - socket()->flush(); // ensure that the write cache is flushed before we switch to ssl } diff --git a/src/core/coreauthhandler.cpp b/src/core/coreauthhandler.cpp index 5942676f..4b2824f5 100644 --- a/src/core/coreauthhandler.cpp +++ b/src/core/coreauthhandler.cpp @@ -68,6 +68,7 @@ void CoreAuthHandler::startSsl() qDebug() << qPrintable(tr("Starting encryption for Client:")) << _peer->description(); connect(sslSocket, SIGNAL(sslErrors(const QList &)), SLOT(onSslErrors())); + sslSocket->flush(); // ensure that the write cache is flushed before we switch to ssl (bug 682) sslSocket->startServerEncryption(); #endif } @@ -148,5 +149,6 @@ void CoreAuthHandler::handle(const Login &msg) disconnect(_peer, 0, this, 0); _peer->setParent(0); // Core needs to take care of this one now! + socket()->flush(); // Make sure all data is sent before handing over the peer (and socket) to the session thread (bug 682) emit handshakeComplete(_peer, uid); } -- 2.20.1