00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef CXPOOL_HH_
00014 # define CXPOOL_HH_
00015
00016 # include <vector>
00017 # include <map>
00018 # include <utility>
00019
00020 # if HAVE_EPOLL
00021 # include <sys/epoll.h>
00022 # else
00023 # include <sys/select.h>
00024 # endif
00025
00027 enum ECxPollFdState {
00028 E_FD_READ_READY,
00029 E_FD_CONNECTION_PENDING,
00030 E_FD_CONNECTION_CLOSED
00031 };
00032
00034 template <typename T>
00035 class CxPool
00036 {
00037 public:
00038 typedef typename std::vector<std::pair<enum ECxPollFdState, T*> > EltList;
00039 typedef typename EltList::iterator ElIter;
00040 typedef typename EltList::const_iterator ConstEltIter;
00041
00042 CxPool(int timeout);
00043 virtual ~CxPool();
00044
00046 void setLock(pthread_mutex_t* lock);
00047
00048 const EltList& poll();
00049 void addElt(T* elt);
00050 void removeElt(T* elt);
00051 int size() const;
00052 void flush();
00053
00054 protected:
00055 typedef typename std::map<int, T*> InternalEltList;
00056 typedef typename InternalEltList::iterator InternalEltIter;
00057
00058 InternalEltList elt_list_;
00059
00060 private:
00061 int timeout_;
00062 pthread_mutex_t* lock_;
00063 EltList ready_list_;
00064
00065 # if HAVE_EPOLL
00066 int epoll_fd_;
00067 # else
00068 struct pollfd* ev_;
00069 int ev_size_;
00070 # endif
00071 };
00072
00073 # include "CxPool.hxx"
00074
00075 #endif