system/EpollFD: use class UniqueFileDescriptor

This commit is contained in:
Max Kellermann 2018-08-22 15:38:22 +02:00
parent 5d0a463f09
commit 98eed1f5ab
2 changed files with 9 additions and 14 deletions

View File

@ -35,7 +35,7 @@
EpollFD::EpollFD()
:fd(::epoll_create1(EPOLL_CLOEXEC))
{
if (fd < 0)
if (!fd.IsDefined())
throw MakeErrno("epoll_create1() failed");
}

View File

@ -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 {