00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef POLLER_GENERIC_H
00028 #define POLLER_GENERIC_H
00029
00030 #include <unistd.h>
00031 #include <poll.h>
00032 #include <vector>
00033 #include <hash_map>
00034 #include <queue>
00035
00036 #include "poller_util.h"
00037
00038 namespace fpoller {
00043 class poller_generic {
00044 private:
00045 struct fd_info {
00046 callback_wrapper reader,writer;
00047 int pollfds_index;
00048 };
00049 typedef std::hash_map<int,fd_info> fd_map;
00050 fd_map fd_map_;
00051 int num_fds_;
00052 std::vector<pollfd> pollfds_;
00053 std::priority_queue<int,std::vector<int>,std::greater<int> > available_;
00054 inline void try_callback(int fd, callback_wrapper &cb, int interest){if (cb.operator->() && cb(fd) == REMOVE) remove(fd,interest);}
00055 public:
00056 poller_generic();
00057 void add(int fd, short interest, callback* cb);
00058 void remove(int fd, short interest);
00059 int poll(int timeout);
00060 };
00061
00062 }
00063
00064 #endif //GENERIC_POLLER_H