Commit 98eed1f5 authored by Max Kellermann's avatar Max Kellermann

system/EpollFD: use class UniqueFileDescriptor

parent 5d0a463f
......@@ -35,7 +35,7 @@
EpollFD::EpollFD()
:fd(::epoll_create1(EPOLL_CLOEXEC))
{
if (fd < 0)
if (!fd.IsDefined())
throw MakeErrno("epoll_create1() failed");
}
......
......@@ -30,20 +30,21 @@
#ifndef EPOLL_FD_HXX
#define EPOLL_FD_HXX
#include "check.h"
#include "UniqueFileDescriptor.hxx"
#include <assert.h>
#include <sys/epoll.h>
#include <unistd.h>
#include <stdint.h>
#include "check.h"
struct epoll_event;
/**
* A class that wraps Linux epoll.
*/
class EpollFD {
const int fd;
UniqueFileDescriptor fd;
public:
/**
......@@ -51,21 +52,15 @@ public:
*/
EpollFD();
~EpollFD() noexcept {
assert(fd >= 0);
::close(fd);
}
EpollFD(const EpollFD &other) = delete;
EpollFD &operator=(const EpollFD &other) = delete;
EpollFD(EpollFD &&) = default;
EpollFD &operator=(EpollFD &&) = default;
int Wait(epoll_event *events, int maxevents, int timeout) noexcept {
return ::epoll_wait(fd, events, maxevents, timeout);
return ::epoll_wait(fd.Get(), events, maxevents, timeout);
}
bool Control(int op, int _fd, epoll_event *event) noexcept {
return ::epoll_ctl(fd, op, _fd, event) >= 0;
return ::epoll_ctl(fd.Get(), op, _fd, event) >= 0;
}
bool Add(int _fd, uint32_t events, void *ptr) noexcept {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment