memgraph/include/io/network/epoll.hpp
Marko Budiselic 35f882644e config is better now (yaml-cpp) + web::Client + web::Logger
Summary:
init struct size problem fix

cast issue bolt::State::init

TCP server bugfix EPOLLET + bolt bug fix

Test Plan: normal

Reviewers: ktf

Subscribers: ktf

Maniphest Tasks: T87

Differential Revision: https://phabricator.tomicevic.com/D2
2016-09-08 12:13:30 +01:00

58 lines
1.0 KiB
C++

#pragma once
#include <malloc.h>
#include <sys/epoll.h>
#include "io/network/socket.hpp"
#include "utils/likely.hpp"
#include "logging/default.hpp"
namespace io
{
class EpollError : BasicException
{
public:
using BasicException::BasicException;
};
class Epoll
{
public:
using Event = struct epoll_event;
Epoll(int flags) :
logger(logging::log->logger("io::Epoll"))
{
epoll_fd = epoll_create1(flags);
if(UNLIKELY(epoll_fd == -1))
throw EpollError("Can't create epoll file descriptor");
}
template <class Stream>
void add(Stream& stream, Event* event)
{
auto status = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, stream, event);
if(UNLIKELY(status))
throw EpollError("Can't add an event to epoll listener.");
}
int wait(Event* events, int max_events, int timeout)
{
return epoll_wait(epoll_fd, events, max_events, timeout);
}
int id() const
{
return epoll_fd;
}
private:
int epoll_fd;
Logger logger;
};
}