diff --git a/src/system/EpollFD.cxx b/src/system/EpollFD.cxx index 62b121ce6..ce0d545ab 100644 --- a/src/system/EpollFD.cxx +++ b/src/system/EpollFD.cxx @@ -35,7 +35,7 @@ EpollFD::EpollFD() :fd(::epoll_create1(EPOLL_CLOEXEC)) { - if (fd < 0) + if (!fd.IsDefined()) throw MakeErrno("epoll_create1() failed"); } diff --git a/src/system/EpollFD.hxx b/src/system/EpollFD.hxx index a3a661361..646af3f7f 100644 --- a/src/system/EpollFD.hxx +++ b/src/system/EpollFD.hxx @@ -30,20 +30,21 @@ #ifndef EPOLL_FD_HXX #define EPOLL_FD_HXX +#include "check.h" +#include "UniqueFileDescriptor.hxx" + #include #include #include #include -#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 {