libzmq  master
ZeroMQ C++ Core Engine (LIBZMQ)
poller_base.hpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
3 
4  This file is part of libzmq, the ZeroMQ core engine in C++.
5 
6  libzmq is free software; you can redistribute it and/or modify it under
7  the terms of the GNU Lesser General Public License (LGPL) as published
8  by the Free Software Foundation; either version 3 of the License, or
9  (at your option) any later version.
10 
11  As a special exception, the Contributors give you permission to link
12  this library with independent modules to produce an executable,
13  regardless of the license terms of these independent modules, and to
14  copy and distribute the resulting executable under terms of your choice,
15  provided that you also meet, for each linked independent module, the
16  terms and conditions of the license of that module. An independent
17  module is a module which is not derived from or based on this library.
18  If you modify this library, you must extend this exception to your
19  version of the library.
20 
21  libzmq is distributed in the hope that it will be useful, but WITHOUT
22  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
24  License for more details.
25 
26  You should have received a copy of the GNU Lesser General Public License
27  along with this program. If not, see <http://www.gnu.org/licenses/>.
28 */
29 
30 #ifndef __ZMQ_POLLER_BASE_HPP_INCLUDED__
31 #define __ZMQ_POLLER_BASE_HPP_INCLUDED__
32 
33 #include <map>
34 
35 #include "clock.hpp"
36 #include "atomic_counter.hpp"
37 
38 namespace zmq
39 {
40 
41  struct i_poll_events;
42 
44  {
45  public:
46 
47  poller_base_t ();
48  virtual ~poller_base_t ();
49 
50  // Returns load of the poller. Note that this function can be
51  // invoked from a different thread!
52  int get_load ();
53 
54  // Add a timeout to expire in timeout_ milliseconds. After the
55  // expiration timer_event on sink_ object will be called with
56  // argument set to id_.
57  void add_timer (int timeout_, zmq::i_poll_events *sink_, int id_);
58 
59  // Cancel the timer created by sink_ object with ID equal to id_.
60  void cancel_timer (zmq::i_poll_events *sink_, int id_);
61 
62  protected:
63 
64  // Called by individual poller implementations to manage the load.
65  void adjust_load (int amount_);
66 
67  // Executes any timers that are due. Returns number of milliseconds
68  // to wait to match the next timer or 0 meaning "no timers".
69  uint64_t execute_timers ();
70 
71  private:
72 
73  // Clock instance private to this I/O thread.
75 
76  // List of active timers.
77  struct timer_info_t
78  {
80  int id;
81  };
82  typedef std::multimap <uint64_t, timer_info_t> timers_t;
83  timers_t timers;
84 
85  // Load of the poller. Currently the number of file descriptors
86  // registered.
88 
91  };
92 
93 }
94 
95 #endif
uint64_t execute_timers()
Definition: poller_base.cpp:79
const poller_base_t & operator=(const poller_base_t &)
virtual ~poller_base_t()
Definition: poller_base.cpp:39
std::multimap< uint64_t, timer_info_t > timers_t
Definition: poller_base.hpp:82
void adjust_load(int amount_)
Definition: poller_base.cpp:50
void add_timer(int timeout_, zmq::i_poll_events *sink_, int id_)
Definition: poller_base.cpp:59
atomic_counter_t load
Definition: poller_base.hpp:87
Definition: address.hpp:35
void cancel_timer(zmq::i_poll_events *sink_, int id_)
Definition: poller_base.cpp:66