VWeb/Source/EPollManager.cpp
Maurice Grönwoldt 5bb68a7d02 Split VWeb into smaller headers
We have no make install support... so we don't need to have everything as a single-header and lib file.
2023-09-16 16:29:03 +02:00

38 lines
932 B
C++

#include "Includes/VWeb.h"
#include <fcntl.h>
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 {
return epoll_wait(m_EpollID, events, maxEvents, -1);
}
} // namespace VWeb