aboutsummaryrefslogtreecommitdiffstats
path: root/src/event/EventFD.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-08-07 10:53:22 +0200
committerMax Kellermann <max@duempel.org>2013-08-07 10:53:22 +0200
commitdb447440ff8973961e1936a6a64ca4971eeeea57 (patch)
treed8208496bbc8d80f614f02998580007b34a987d0 /src/event/EventFD.cxx
parentb70d38dc10868a7ddfac2df7001be36fc37fc21c (diff)
downloadmpd-db447440ff8973961e1936a6a64ca4971eeeea57.tar.gz
mpd-db447440ff8973961e1936a6a64ca4971eeeea57.tar.xz
mpd-db447440ff8973961e1936a6a64ca4971eeeea57.zip
event/Event{Pipe,FD}: auto-create in constructor
Errors are fatal now. This makes the class a lot easier to use.
Diffstat (limited to '')
-rw-r--r--src/event/EventFD.cxx25
1 files changed, 9 insertions, 16 deletions
diff --git a/src/event/EventFD.cxx b/src/event/EventFD.cxx
index dba80d9be..716ff80ae 100644
--- a/src/event/EventFD.cxx
+++ b/src/event/EventFD.cxx
@@ -21,33 +21,26 @@
#ifdef USE_EVENTFD
#include "EventFD.hxx"
#include "system/fd_util.h"
+#include "system/FatalError.hxx"
#include "gcc.h"
+#include <assert.h>
#include <unistd.h>
#include <sys/eventfd.h>
-#ifdef WIN32
-static bool PoorSocketPair(int fd[2]);
-#endif
-
-bool
-EventFD::Create()
+EventFD::EventFD()
+ :fd(eventfd_cloexec_nonblock(0, 0))
{
- assert(fd == -1);
-
- fd = eventfd_cloexec_nonblock(0, 0);
- return fd >= 0;
+ if (fd < 0)
+ FatalSystemError("eventfd() failed");
}
-void
-EventFD::Destroy()
+EventFD::~EventFD()
{
- close(fd);
+ assert(fd >= 0);
-#ifndef NDEBUG
- fd = -1;
-#endif
+ close(fd);
}
bool