![]() |
libzmq master
The Intelligent Transport Layer
|
00001 /* 00002 Copyright (c) 2010-2011 250bpm s.r.o. 00003 Copyright (c) 2010-2011 Other contributors as noted in the AUTHORS file 00004 00005 This file is part of 0MQ. 00006 00007 0MQ is free software; you can redistribute it and/or modify it under 00008 the terms of the GNU Lesser General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 0MQ is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 #ifndef __ZMQ_POLLER_BASE_HPP_INCLUDED__ 00022 #define __ZMQ_POLLER_BASE_HPP_INCLUDED__ 00023 00024 #include <map> 00025 00026 #include "clock.hpp" 00027 #include "atomic_counter.hpp" 00028 00029 namespace zmq 00030 { 00031 00032 class poller_base_t 00033 { 00034 public: 00035 00036 poller_base_t (); 00037 virtual ~poller_base_t (); 00038 00039 // Returns load of the poller. Note that this function can be 00040 // invoked from a different thread! 00041 int get_load (); 00042 00043 // Add a timeout to expire in timeout_ milliseconds. After the 00044 // expiration timer_event on sink_ object will be called with 00045 // argument set to id_. 00046 void add_timer (int timeout_, struct i_poll_events *sink_, int id_); 00047 00048 // Cancel the timer created by sink_ object with ID equal to id_. 00049 void cancel_timer (struct i_poll_events *sink_, int id_); 00050 00051 protected: 00052 00053 // Called by individual poller implementations to manage the load. 00054 void adjust_load (int amount_); 00055 00056 // Executes any timers that are due. Returns number of milliseconds 00057 // to wait to match the next timer or 0 meaning "no timers". 00058 uint64_t execute_timers (); 00059 00060 private: 00061 00062 // Clock instance private to this I/O thread. 00063 clock_t clock; 00064 00065 // List of active timers. 00066 struct timer_info_t 00067 { 00068 struct i_poll_events *sink; 00069 int id; 00070 }; 00071 typedef std::multimap <uint64_t, timer_info_t> timers_t; 00072 timers_t timers; 00073 00074 // Load of the poller. Currently the number of file descriptors 00075 // registered. 00076 atomic_counter_t load; 00077 00078 poller_base_t (const poller_base_t&); 00079 const poller_base_t &operator = (const poller_base_t&); 00080 }; 00081 00082 } 00083 00084 #endif