From 238640a526c419392bf2df95de196db89ea6eb73 Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Sun, 26 Sep 2010 21:42:23 +0200 Subject: timers properly implemented --- src/poller_base.hpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/poller_base.hpp') 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 + +#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 timers_t; + timers_t timers; + // Load of the poller. Currently the number of file descriptors // registered. atomic_counter_t load; -- cgit v1.2.3