From 3e58a6052200a4bcf1fbc1af0683650dc4b86145 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 25 Jan 2015 19:26:20 +0100 Subject: Avoid shutting down the synchronizer all the time. --- synchronizer/listener.cpp | 23 +++++++++++++++-------- synchronizer/listener.h | 1 + 2 files changed, 16 insertions(+), 8 deletions(-) (limited to 'synchronizer') diff --git a/synchronizer/listener.cpp b/synchronizer/listener.cpp index 1294c76..f52e48c 100644 --- a/synchronizer/listener.cpp +++ b/synchronizer/listener.cpp @@ -60,13 +60,23 @@ Listener::Listener(const QString &resourceName, QObject *parent) log(QString("Listening on %1").arg(m_server->serverName())); } + m_checkConnectionsTimer = new QTimer; + m_checkConnectionsTimer->setSingleShot(true); + m_checkConnectionsTimer->setInterval(1000); + connect(m_checkConnectionsTimer, &QTimer::timeout, [this]() { + if (m_connections.isEmpty()) { + log(QString("No connections, shutting down.")); + m_server->close(); + emit noClients(); + } + }); + //TODO: experiment with different timeouts - // or even just drop down to invoking the method queued? - m_clientBufferProcessesTimer->setInterval(10); + // or even just drop down to invoking the method queued? => invoke queued unless we need throttling + m_clientBufferProcessesTimer->setInterval(0); m_clientBufferProcessesTimer->setSingleShot(true); connect(m_clientBufferProcessesTimer, &QTimer::timeout, this, &Listener::processClientBuffers); - QTimer::singleShot(2000, this, SLOT(checkConnections())); } Listener::~Listener() @@ -102,6 +112,7 @@ void Listener::acceptConnection() m_connections << client; connect(socket, &QLocalSocket::disconnected, this, &Listener::clientDropped); + m_checkConnectionsTimer->stop(); } @@ -128,11 +139,7 @@ void Listener::clientDropped() void Listener::checkConnections() { - if (m_connections.isEmpty()) { - log(QString("No connections, shutting down.")); - m_server->close(); - emit noClients(); - } + m_checkConnectionsTimer->start(); } void Listener::readFromSocket() diff --git a/synchronizer/listener.h b/synchronizer/listener.h index 4c35191..f1241c7 100644 --- a/synchronizer/listener.h +++ b/synchronizer/listener.h @@ -91,5 +91,6 @@ private: Akonadi2::Resource *m_resource; Akonadi2::Pipeline *m_pipeline; QTimer *m_clientBufferProcessesTimer; + QTimer *m_checkConnectionsTimer; int m_messageId; }; -- cgit v1.2.3