Poller.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 #ifndef HH_SENF_Scheduler_Poller_
18 #define HH_SENF_Scheduler_Poller_ 1
19 
20 // Custom includes
21 #include <sys/epoll.h>
22 #include <boost/noncopyable.hpp>
23 #include <boost/iterator/transform_iterator.hpp>
24 #include <boost/range/iterator_range.hpp>
25 
26 //#include "Poller.mpp"
27 //-/////////////////////////////////////////////////////////////////////////////////////////////////
28 
29 namespace senf {
30 namespace scheduler {
31 namespace detail {
32 
41  template <class Value>
42  class Poller
43  : boost::noncopyable
44  {
45  struct GetPollResult
46  {
47  typedef std::pair<int, Value*> result_type;
48  result_type operator()(epoll_event const &) const;
49  };
50 
51  static int const NumEvents = 8;
52 
53  public:
54  //-////////////////////////////////////////////////////////////////////////
55  // Types
56 
57  typedef Value value_type;
58  typedef boost::transform_iterator<GetPollResult, epoll_event*> iterator;
59  typedef boost::iterator_range<iterator> range;
60 
61  enum Events {
62  EV_READ = EPOLLIN, EV_PRIO = EPOLLPRI, EV_WRITE = EPOLLOUT,
63  EV_HUP = EPOLLHUP, EV_ERR = EPOLLERR
64  };
65 
66  //-////////////////////////////////////////////////////////////////////////
68  //\{
69 
70  Poller();
71  ~Poller();
72 
73  //\}
74  //-////////////////////////////////////////////////////////////////////////
75 
76  bool set(int fd, int events, Value * data);
78 
81  void remove(int fd);
82  range wait();
83 
86  void timeout(int t);
87  int timeout() const;
88 
89  private:
90  int epollFd_;
91  int timeout_;
92  };
93 
94 
95 }}}
96 
97 //-/////////////////////////////////////////////////////////////////////////////////////////////////
98 //#include "Poller.cci"
99 #include "Poller.ct"
100 #include "Poller.cti"
101 #endif
102 
103 
104 // Local Variables:
105 // mode: c++
106 // fill-column: 100
107 // comment-column: 40
108 // c-file-style: "senf"
109 // indent-tabs-mode: nil
110 // ispell-local-dictionary: "american"
111 // compile-command: "scons -u test"
112 // End:
u8 data[SPECTRAL_HT20_NUM_BINS]
boost::iterator_range< iterator > range
Definition: Poller.hh:59
int timeout() const
Current event timeout.
boost::transform_iterator< GetPollResult, epoll_event * > iterator
Definition: Poller.hh:58
range wait()
Wait for one event.
Epoll abstraction.
Definition: Poller.hh:42