summaryrefslogtreecommitdiff
path: root/src/poller_base.hpp
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2010-09-26 21:42:23 +0200
committerMartin Sustrik <sustrik@250bpm.com>2010-09-26 21:42:23 +0200
commit238640a526c419392bf2df95de196db89ea6eb73 (patch)
tree8434dfc49117739f1d344a3d96a4957f6206d9d0 /src/poller_base.hpp
parent8d7bf6684cbb9625ec7c963b8867e2411b49eb57 (diff)
timers properly implemented
Diffstat (limited to 'src/poller_base.hpp')
-rw-r--r--src/poller_base.hpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/poller_base.hpp b/src/poller_base.hpp
index 0b0d53d..f607d94 100644
--- a/src/poller_base.hpp
+++ b/src/poller_base.hpp
@@ -20,6 +20,9 @@
#ifndef __ZMQ_POLLER_BASE_HPP_INCLUDED__
#define __ZMQ_POLLER_BASE_HPP_INCLUDED__
+#include <map>
+
+#include "clock.hpp"
#include "atomic_counter.hpp"
namespace zmq
@@ -36,13 +39,37 @@ namespace zmq
// invoked from a different thread!
int get_load ();
+ // Add a timeout to expire in timeout_ milliseconds. After the
+ // expiration timer_event on sink_ object will be called with
+ // argument set to id_.
+ void add_timer (int timeout_, struct i_poll_events *sink_, int id_);
+
+ // Cancel the timer created by sink_ object with ID equal to id_.
+ void cancel_timer (struct i_poll_events *sink_, int id_);
+
protected:
// Called by individual poller implementations to manage the load.
void adjust_load (int amount_);
+ // Executes any timers that are due. Returns number of milliseconds
+ // to wait to match the next timer or 0 meaning "no timers".
+ uint64_t execute_timers ();
+
private:
+ // Clock instance private to this I/O thread.
+ clock_t clock;
+
+ // List of active timers.
+ struct timer_info_t
+ {
+ struct i_poll_events *sink;
+ int id;
+ };
+ typedef std::multimap <uint64_t, timer_info_t> timers_t;
+ timers_t timers;
+
// Load of the poller. Currently the number of file descriptors
// registered.
atomic_counter_t load;