a8/a8/eventfd.cc
2020-01-09 15:59:26 +08:00

60 lines
888 B
C++

#include <unistd.h>
#include <sys/eventfd.h>
#include <a8/a8.h>
#include <a8/eventfd.h>
namespace a8
{
EventFD::EventFD()
{
fd_ = ::eventfd(0, 0);
if (fd_ == a8::INVALID_FD) {
abort();
}
}
EventFD::~EventFD()
{
::close(fd_);
fd_ = a8::INVALID_FD;
}
void EventFD::Init(void* context)
{
context_ = context;
}
void EventFD::Write(unsigned long long value)
{
eventfd_write(fd_, value);
}
void EventFD::SetEpollFd(int epoll_fd)
{
epoll_fd_ = epoll_fd;
}
void EventFD::DoRecv()
{
eventfd_t value = 0;
::eventfd_read(fd_, &value);
if (OnEvent) {
OnEvent(context_, value);
}
}
void EventFD::DoSend()
{
abort();
}
void EventFD::DoError()
{
abort();
}
}