00001 // $Id: Poller.hh 1742 2010-11-04 14:51:56Z g0dil $ 00002 // 00003 // Copyright (C) 2008 00004 // Fraunhofer (FOKUS) 00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY 00006 // Stefan Bund <g0dil@berlios.de> 00007 // 00008 // This program is free software; you can redistribute it and/or modify 00009 // it under the terms of the GNU General Public License as published by 00010 // the Free Software Foundation; either version 2 of the License, or 00011 // (at your option) any later version. 00012 // 00013 // This program is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with this program; if not, write to the 00020 // Free Software Foundation, Inc., 00021 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 00026 #ifndef HH_SENF_Scheduler_Poller_ 00027 #define HH_SENF_Scheduler_Poller_ 1 00028 00029 // Custom includes 00030 #include <sys/epoll.h> 00031 #include <boost/utility.hpp> 00032 #include <boost/iterator/transform_iterator.hpp> 00033 #include <boost/range/iterator_range.hpp> 00034 00035 //#include "Poller.mpp" 00036 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00037 00038 namespace senf { 00039 namespace scheduler { 00040 namespace detail { 00041 00050 template <class Value> 00051 class Poller 00052 : boost::noncopyable 00053 { 00054 struct GetPollResult 00055 { 00056 typedef std::pair<int, Value*> result_type; 00057 result_type operator()(epoll_event const &) const; 00058 }; 00059 00060 static int const NumEvents = 8; 00061 00062 public: 00063 //-//////////////////////////////////////////////////////////////////////// 00064 // Types 00065 00066 typedef Value value_type; 00067 typedef boost::transform_iterator<GetPollResult, epoll_event*> iterator; 00068 typedef boost::iterator_range<iterator> range; 00069 00070 enum Events { 00071 EV_READ = EPOLLIN, EV_PRIO = EPOLLPRI, EV_WRITE = EPOLLOUT, 00072 EV_HUP = EPOLLHUP, EV_ERR = EPOLLERR 00073 }; 00074 00075 //-//////////////////////////////////////////////////////////////////////// 00077 //\{ 00078 00079 Poller(); 00080 ~Poller(); 00081 00082 //\} 00083 //-//////////////////////////////////////////////////////////////////////// 00084 00085 bool set(int fd, int events, Value * data); 00086 00089 void remove(int fd); 00090 range wait(); 00091 00094 void timeout(int t); 00095 int timeout() const; 00096 00097 private: 00098 int epollFd_; 00099 int timeout_; 00100 }; 00101 00102 00103 }}} 00104 00105 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00106 //#include "Poller.cci" 00107 #include "Poller.ct" 00108 #include "Poller.cti" 00109 #endif 00110 00111 00112 // Local Variables: 00113 // mode: c++ 00114 // fill-column: 100 00115 // comment-column: 40 00116 // c-file-style: "senf" 00117 // indent-tabs-mode: nil 00118 // ispell-local-dictionary: "american" 00119 // compile-command: "scons -u test" 00120 // End: