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////////////////////////////////////////
41 /** \brief Epoll abstraction
43 This class provides a more convenient interface to the epoll() API. File descriptors are
44 registered with pointers to a parameterized event type. After waiting for an event, the
45 Poller allows to iterate over the event instances for all posted events.
47 \tparam Value Event type
49 template <class Value>
55 typedef std::pair<int, Value*> result_type;
56 result_type operator()(epoll_event const &) const;
59 static int const NumEvents = 8;
62 ///////////////////////////////////////////////////////////////////////////
65 typedef Value value_type;
66 typedef boost::transform_iterator<GetPollResult, epoll_event*> iterator;
67 typedef boost::iterator_range<iterator> range;
70 EV_READ = EPOLLIN, EV_PRIO = EPOLLPRI, EV_WRITE = EPOLLOUT,
71 EV_HUP = EPOLLHUP, EV_ERR = EPOLLERR
74 ///////////////////////////////////////////////////////////////////////////
75 ///\name Structors and default members
82 ///////////////////////////////////////////////////////////////////////////
84 bool set(int fd, int events, Value * data); ///< Set file descriptor event data and mask
85 /**< The Poller does \e not own \a data. The value is owned
86 by some external entity (the dispatcher to be more
88 void remove(int fd); ///< Remove file descriptor
89 range wait(); ///< Wait for one event
90 /**< \returns a range of iterators which iterate over the
91 data values registered with the event */
93 void timeout(int t); ///< Set event timeout to \a t milliseconds
94 int timeout() const; ///< Current event timeout
104 ///////////////////////////////hh.e////////////////////////////////////////
105 //#include "Poller.cci"
107 #include "Poller.cti"
114 // comment-column: 40
115 // c-file-style: "senf"
116 // indent-tabs-mode: nil
117 // ispell-local-dictionary: "american"
118 // compile-command: "scons -u test"