diff options
Diffstat (limited to 'src/poller_base.hpp')
-rw-r--r-- | src/poller_base.hpp | 27 |
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; |