summaryrefslogtreecommitdiffstats
path: root/synchronizer
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-01-25 19:26:20 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-01-25 19:26:20 +0100
commit3e58a6052200a4bcf1fbc1af0683650dc4b86145 (patch)
treea58fec6fb088e92f6c38deb390bcc2a4a15cdddd /synchronizer
parent35ae961b37dfc860ab52edd69093d71c5b2a732f (diff)
downloadsink-3e58a6052200a4bcf1fbc1af0683650dc4b86145.tar.gz
sink-3e58a6052200a4bcf1fbc1af0683650dc4b86145.zip
Avoid shutting down the synchronizer all the time.
Diffstat (limited to 'synchronizer')
-rw-r--r--synchronizer/listener.cpp23
-rw-r--r--synchronizer/listener.h1
2 files changed, 16 insertions, 8 deletions
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)
60 log(QString("Listening on %1").arg(m_server->serverName())); 60 log(QString("Listening on %1").arg(m_server->serverName()));
61 } 61 }
62 62
63 m_checkConnectionsTimer = new QTimer;
64 m_checkConnectionsTimer->setSingleShot(true);
65 m_checkConnectionsTimer->setInterval(1000);
66 connect(m_checkConnectionsTimer, &QTimer::timeout, [this]() {
67 if (m_connections.isEmpty()) {
68 log(QString("No connections, shutting down."));
69 m_server->close();
70 emit noClients();
71 }
72 });
73
63 //TODO: experiment with different timeouts 74 //TODO: experiment with different timeouts
64 // or even just drop down to invoking the method queued? 75 // or even just drop down to invoking the method queued? => invoke queued unless we need throttling
65 m_clientBufferProcessesTimer->setInterval(10); 76 m_clientBufferProcessesTimer->setInterval(0);
66 m_clientBufferProcessesTimer->setSingleShot(true); 77 m_clientBufferProcessesTimer->setSingleShot(true);
67 connect(m_clientBufferProcessesTimer, &QTimer::timeout, 78 connect(m_clientBufferProcessesTimer, &QTimer::timeout,
68 this, &Listener::processClientBuffers); 79 this, &Listener::processClientBuffers);
69 QTimer::singleShot(2000, this, SLOT(checkConnections()));
70} 80}
71 81
72Listener::~Listener() 82Listener::~Listener()
@@ -102,6 +112,7 @@ void Listener::acceptConnection()
102 m_connections << client; 112 m_connections << client;
103 connect(socket, &QLocalSocket::disconnected, 113 connect(socket, &QLocalSocket::disconnected,
104 this, &Listener::clientDropped); 114 this, &Listener::clientDropped);
115 m_checkConnectionsTimer->stop();
105 116
106} 117}
107 118
@@ -128,11 +139,7 @@ void Listener::clientDropped()
128 139
129void Listener::checkConnections() 140void Listener::checkConnections()
130{ 141{
131 if (m_connections.isEmpty()) { 142 m_checkConnectionsTimer->start();
132 log(QString("No connections, shutting down."));
133 m_server->close();
134 emit noClients();
135 }
136} 143}
137 144
138void Listener::readFromSocket() 145void 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:
91 Akonadi2::Resource *m_resource; 91 Akonadi2::Resource *m_resource;
92 Akonadi2::Pipeline *m_pipeline; 92 Akonadi2::Pipeline *m_pipeline;
93 QTimer *m_clientBufferProcessesTimer; 93 QTimer *m_clientBufferProcessesTimer;
94 QTimer *m_checkConnectionsTimer;
94 int m_messageId; 95 int m_messageId;
95}; 96};