// // Copyright @ 2015 Hangzhou Topzen Ltd. // Author: Dong Xiaohua (dongxh@hztopzen.com) @ 2015-08 // #ifndef __EPOLL_H #define __EPOLL_H #if defined(LINUX) #include "BaseTypes.h" #include "BaseHeaders.h" #include "SockAddress.h" #include "Locks.h" #include namespace tzc { class IOEventHandler { public: IOEventHandler() {} virtual ~IOEventHandler() {} virtual void Recvice() = 0; virtual void Send() = 0; virtual void Exception(TZ_Int32 iEvent) = 0; }; class Epoll { public: #define DEFAILT_MAX_CONN 1024 typedef enum __EventMode { Mode_LTRead = EPOLLIN, Mode_LTWrite = EPOLLOUT, Mode_ETRead = EPOLLIN | EPOLLET, Mode_ETWrite = EPOLLOUT | EPOLLET, Mode_PRI = EPOLLPRI, Mode_Err = EPOLLERR, Mode_Hup = EPOLLHUP } EventMode_E; public: Epoll(TZ_Int32 iTimeout = 1, TZ_Int32 iMaxConn = DEFAILT_MAX_CONN); ~Epoll(); TZ_Int32 EpollInitialize(); TZ_Int32 EpollAdd(TZ_Int32 iSockFd, TZ_Int32 iEventMode, IOEventHandler *pHandler); TZ_Int32 EpollModify(TZ_Int32 iSockFd, TZ_Int32 iEventMode, IOEventHandler *pHandler); TZ_Int32 EpollDelete(TZ_Int32 iSockFd, TZ_Int32 iEventMode, IOEventHandler *pHandler); void EpollWait(); void EpollWait(TZ_Int32 iTimeout); private: typedef struct epoll_event EpollEvent_S; const TZ_Int32 m_iMaxConn; TZ_Int32 m_iEpollFd; TZ_Int32 m_iTimeout; EpollEvent_S * m_pEvents; Mutex m_mtxEvent; std::map m_mapEventHandler; }; }; // namespace tzc #endif #endif /* ----- #ifndef __EPOLL_H ----- */