VWeb/Source/EPollManager.cpp

38 lines
932 B
C++
Raw Normal View History

#include "Includes/VWeb.h"
#include <fcntl.h>
2022-08-23 14:13:21 +02:00
namespace VWeb {
EPollManager::EPollManager() {
m_EpollID = epoll_create1(0);
if (m_EpollID < 0)
exit(49);
unsigned int flags = fcntl(m_EpollID, F_GETFL, 0);
flags |= O_NONBLOCK;
fcntl(m_EpollID, F_SETFL, flags);
}
EPollManager::~EPollManager() { close(m_EpollID); }
bool EPollManager::Dispatch(int sock, uint32_t eventType) const {
struct epoll_event event {
0
};
event.data.fd = sock;
event.events = eventType;
return epoll_ctl(m_EpollID, EPOLL_CTL_ADD, sock, &event) != -1;
}
bool EPollManager::UpdateEvents(int sock, uint32_t eventType) const {
struct epoll_event event {
0
};
event.data.fd = sock;
event.events = eventType;
return epoll_ctl(m_EpollID, EPOLL_CTL_MOD, sock, &event) != -1;
}
int EPollManager::Wait(int maxEvents, epoll_event *events) const {
2023-09-02 14:17:56 +02:00
return epoll_wait(m_EpollID, events, maxEvents, -1);
2022-08-23 14:13:21 +02:00
}
} // namespace VWeb