summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Seigo <aseigo@kde.org>2014-11-21 13:14:20 +0100
committerAaron Seigo <aseigo@kde.org>2014-11-21 13:14:20 +0100
commitc52b181c3382a754b10f0457763e0364463592ad (patch)
tree63137816f7c9736a52df4480f46f4d31df47d3e3
parented20c3082d4fd5e90703e4d6c37093dcecb5cfd1 (diff)
downloadsink-c52b181c3382a754b10f0457763e0364463592ad.tar.gz
sink-c52b181c3382a754b10f0457763e0364463592ad.zip
close if we don't get a connection in the first two seconds
-rw-r--r--resource/listener.cpp13
-rw-r--r--resource/listener.h6
2 files changed, 19 insertions, 0 deletions
diff --git a/resource/listener.cpp b/resource/listener.cpp
index efdfe3e..e68b3d4 100644
--- a/resource/listener.cpp
+++ b/resource/listener.cpp
@@ -3,6 +3,7 @@
3#include "common/console.h" 3#include "common/console.h"
4 4
5#include <QLocalSocket> 5#include <QLocalSocket>
6#include <QTimer>
6 7
7Listener::Listener(const QString &resource, QObject *parent) 8Listener::Listener(const QString &resource, QObject *parent)
8 : QObject(parent), 9 : QObject(parent),
@@ -23,6 +24,8 @@ Listener::Listener(const QString &resource, QObject *parent)
23 if (m_server->isListening()) { 24 if (m_server->isListening()) {
24 Console::main()->log(QString("Listening on %1").arg(m_server->serverName())); 25 Console::main()->log(QString("Listening on %1").arg(m_server->serverName()));
25 } 26 }
27
28 QTimer::singleShot(2000, this, SLOT(checkConnections()));
26} 29}
27 30
28Listener::~Listener() 31Listener::~Listener()
@@ -68,4 +71,14 @@ void Listener::clientDropped()
68 break; 71 break;
69 } 72 }
70 } 73 }
74
75 checkConnections();
76}
77
78void Listener::checkConnections()
79{
80 if (m_connections.isEmpty()) {
81 m_server->close();
82 emit noClients();
83 }
71} 84}
diff --git a/resource/listener.h b/resource/listener.h
index 79c7ba5..2fbd75c 100644
--- a/resource/listener.h
+++ b/resource/listener.h
@@ -20,16 +20,22 @@ public:
20 20
21class Listener : public QObject 21class Listener : public QObject
22{ 22{
23 Q_OBJECT
24
23public: 25public:
24 Listener(const QString &resourceName, QObject *parent = 0); 26 Listener(const QString &resourceName, QObject *parent = 0);
25 ~Listener(); 27 ~Listener();
26 28
29Q_SIGNALS:
30 void noClients();
31
27public Q_SLOTS: 32public Q_SLOTS:
28 void closeAllConnections(); 33 void closeAllConnections();
29 34
30private Q_SLOTS: 35private Q_SLOTS:
31 void acceptConnection(); 36 void acceptConnection();
32 void clientDropped(); 37 void clientDropped();
38 void checkConnections();
33 39
34private: 40private:
35 QLocalServer *m_server; 41 QLocalServer *m_server;