summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Network/BoostTimer.cpp2
-rw-r--r--Swiften/Network/Timer.h17
-rw-r--r--Swiften/StreamStack/WhitespacePingLayer.cpp2
3 files changed, 19 insertions, 2 deletions
diff --git a/Swiften/Network/BoostTimer.cpp b/Swiften/Network/BoostTimer.cpp
index 65e7712..ab6fbe0 100644
--- a/Swiften/Network/BoostTimer.cpp
+++ b/Swiften/Network/BoostTimer.cpp
@@ -32,8 +32,6 @@ void BoostTimer::handleTimerTick(const boost::system::error_code& error) {
}
else {
eventLoop->postEvent(boost::bind(boost::ref(onTick)), shared_from_this());
- timer.expires_from_now(boost::posix_time::milliseconds(timeout));
- timer.async_wait(boost::bind(&BoostTimer::handleTimerTick, shared_from_this(), boost::asio::placeholders::error));
}
}
diff --git a/Swiften/Network/Timer.h b/Swiften/Network/Timer.h
index 278a8fb..d44a00d 100644
--- a/Swiften/Network/Timer.h
+++ b/Swiften/Network/Timer.h
@@ -9,15 +9,32 @@
#include "Swiften/Base/boost_bsignals.h"
namespace Swift {
+ /**
+ * A class for triggering an event after a given period.
+ */
class Timer {
public:
typedef boost::shared_ptr<Timer> ref;
virtual ~Timer();
+ /**
+ * Starts the timer.
+ *
+ * After the given period, onTick() will be called.
+ */
virtual void start() = 0;
+
+ /**
+ * Cancels the timer.
+ *
+ * If the timer was started, onTick() will no longer be called.
+ */
virtual void stop() = 0;
+ /**
+ * Emitted when the timer expires.
+ */
boost::signal<void ()> onTick;
};
}
diff --git a/Swiften/StreamStack/WhitespacePingLayer.cpp b/Swiften/StreamStack/WhitespacePingLayer.cpp
index 2adfcea..a99f300 100644
--- a/Swiften/StreamStack/WhitespacePingLayer.cpp
+++ b/Swiften/StreamStack/WhitespacePingLayer.cpp
@@ -29,7 +29,9 @@ void WhitespacePingLayer::handleDataRead(const ByteArray& data) {
}
void WhitespacePingLayer::handleTimerTick() {
+ timer->stop();
onWriteData(" ");
+ timer->start();
}
void WhitespacePingLayer::setActive() {