4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief Poller public header */
30 #include <sys/epoll.h>
31 #include <boost/utility.hpp>
32 #include <boost/iterator/transform_iterator.hpp>
33 #include <boost/range/iterator_range.hpp>
35 //#include "Poller.mpp"
36 ///////////////////////////////hh.p////////////////////////////////////////
42 /** \brief Epoll abstraction
44 This class provides a more convenient interface to the epoll() API. File descriptors are
45 registered with pointers to a parameterized event type. After waiting for an event, the
46 Poller allows to iterate over the event instances for all posted events.
48 \tparam Value Event type
50 template <class Value>
56 typedef std::pair<int, Value*> result_type;
57 result_type operator()(epoll_event const &) const;
60 static int const NumEvents = 8;
63 ///////////////////////////////////////////////////////////////////////////
66 typedef Value value_type;
67 typedef boost::transform_iterator<GetPollResult, epoll_event*> iterator;
68 typedef boost::iterator_range<iterator> range;
71 EV_READ = EPOLLIN, EV_PRIO = EPOLLPRI, EV_WRITE = EPOLLOUT,
72 EV_HUP = EPOLLHUP, EV_ERR = EPOLLERR
75 ///////////////////////////////////////////////////////////////////////////
76 ///\name Structors and default members
83 ///////////////////////////////////////////////////////////////////////////
85 bool set(int fd, int events, Value * data); ///< Set file descriptor event data and mask
86 /**< The Poller does \e not own \a data. The value is owned
87 by some external entity (the dispatcher to be more
89 void remove(int fd); ///< Remove file descriptor
90 range wait(); ///< Wait for one event
91 /**< \returns a range of iterators which iterate over the
92 data values registered with the event */
94 void timeout(int t); ///< Set event timeout to \a t milliseconds
95 int timeout() const; ///< Current event timeout
105 ///////////////////////////////hh.e////////////////////////////////////////
106 //#include "Poller.cci"
108 #include "Poller.cti"
115 // comment-column: 40
116 // c-file-style: "senf"
117 // indent-tabs-mode: nil
118 // ispell-local-dictionary: "american"
119 // compile-command: "scons -u test"