37 size_t _currentEventIndex;
41 uint32_t ToNativeFlags(uint32_t eventflags);
42 uint32_t FromNativeFlags(uint32_t eventflags);
47 virtual HRESULT Add(
int fd, uint32_t eventflags);
75 uint32_t CEpoll::ToNativeFlags(uint32_t eventflags)
93 uint32_t CEpoll::FromNativeFlags(uint32_t eventflags)
111 HRESULT CEpoll::Initialize(
size_t maxSockets)
119 _epollfd = epoll_create(maxSockets);
123 _sizeEvents = maxSockets;
124 _events =
new epoll_event[maxSockets];
129 _currentEventIndex = 0;
150 _currentEventIndex = 0;
156 HRESULT CEpoll::Add(
int fd, uint32_t eventflags)
166 ev.events = ToNativeFlags(eventflags);
168 ChkIfA(epoll_ctl(_epollfd, EPOLL_CTL_ADD, fd, &ev) == -1,
ERRNOHR);
187 ChkIfA(epoll_ctl(_epollfd, EPOLL_CTL_DEL, fd, &ev) == -1,
ERRNOHR);
192 HRESULT CEpoll::ChangeEventSet(
int fd, uint32_t eventflags)
201 ev.events = ToNativeFlags(eventflags);
203 ChkIfA(epoll_ctl(_epollfd, EPOLL_CTL_MOD, fd, &ev) == -1,
ERRNOHR);
209 HRESULT CEpoll::WaitForNextEvent(
PollEvent* pPollEvent,
int timeoutMilliseconds)
212 epoll_event *pEvent = NULL;
217 if (_currentEventIndex >= _pendingCount)
219 _currentEventIndex = 0;
222 ret = ::epoll_wait(_epollfd, _events, _sizeEvents, timeoutMilliseconds);
226 _pendingCount = (size_t)ret;
230 pEvent = &_events[_currentEventIndex];
231 _currentEventIndex++;
234 pPollEvent->
fd = pEvent->data.fd;
235 pPollEvent->
eventflags = FromNativeFlags(pEvent->events);
260 uint32_t ToNativeFlags(uint32_t eventflags);
261 uint32_t FromNativeFlags(uint32_t eventflags);
266 virtual HRESULT Initialize(
size_t maxSockets);
268 virtual HRESULT Add(
int fd, uint32_t eventflags);
269 virtual HRESULT Remove(
int fd);
270 virtual HRESULT ChangeEventSet(
int fd, uint32_t eventflags);
271 virtual HRESULT WaitForNextEvent(
PollEvent* pPollEvent,
int timeoutMilliseconds);
296 if (eventflags & IPOLLING_READ) result |= POLLIN;
297 if (eventflags & IPOLLING_WRITE) result |= POLLOUT;
299 if (eventflags & IPOLLING_RDHUP) result |= POLLRDHUP;
301 if (eventflags & IPOLLING_HUP) result |= POLLHUP;
302 if (eventflags & IPOLLING_PRI) result |= POLLPRI;
328 _fds.reserve(maxSockets);
350 size_t pos =
_fds.size();
370 volatile size_t* pPos = NULL;
372 size_t size =
_fds.size();
418 size_t size =
_fds.size();
440 size_t size =
_fds.size();
460 list = &
_fds.front();
462 ret = poll(list, size, timeoutMilliseconds);
481 size_t size =
_fds.size();
483 pollfd* list = &
_fds.front();
496 for (
size_t index = 0; index < size; index++)
498 size_t slotindex = (index +
_rotation) % size;
500 if (list[slotindex].revents)
502 pEvent->
fd = list[slotindex].fd;
504 list[slotindex].revents = 0;
543 ChkA(CEpoll::CreateInstance(maxSockets, ppPolling));
virtual HRESULT ChangeEventSet(int fd, uint32_t eventflags)
const uint32_t IPOLLING_TYPE_EPOLL
uint32_t ToNativeFlags(uint32_t eventflags)
virtual HRESULT WaitForNextEvent(PollEvent *pPollEvent, int timeoutMilliseconds)=0
const uint32_t IPOLLING_PRI
const uint32_t IPOLLING_RDHUP
virtual HRESULT ChangeEventSet(int fd, uint32_t eventflags)=0
virtual HRESULT Initialize(size_t maxSockets)
HRESULT CreatePollingInstance(uint32_t type, size_t maxSockets, IPolling **ppPolling)
const uint32_t IPOLLING_TYPE_POLL
const uint32_t IPOLLING_TYPE_BEST
virtual HRESULT Close()=0
const uint32_t IPOLLING_ERROR
const uint32_t IPOLLING_WRITE
#define ADDREF_AND_RELEASE_IMPL()
int Insert(const K &key, V &value)
#define ChkIf(expr, hrerror)
virtual HRESULT Add(int fd, uint32_t eventflags)=0
const uint32_t IPOLLING_READ
virtual HRESULT Initialize(size_t maxSockets)=0
virtual HRESULT Remove(int fd)=0
const uint32_t IPOLLING_EDGETRIGGER
virtual HRESULT Add(int fd, uint32_t eventflags)
virtual HRESULT Remove(int fd)
FastHashDynamic< int, size_t > _hashtable
uint32_t FromNativeFlags(uint32_t eventflags)
std::vector< pollfd > _fds
int InitTable(size_t fsize, size_t tsize)
bool FindNextEvent(PollEvent *pEvent)
const uint32_t IPOLLING_HUP
static HRESULT CreateInstance(I **ppI)
virtual HRESULT WaitForNextEvent(PollEvent *pPollEvent, int timeoutMilliseconds)
#define ChkIfA(expr, hrerror)