diff options
author | Max Kellermann <max@duempel.org> | 2013-08-07 10:53:22 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-08-07 10:53:22 +0200 |
commit | db447440ff8973961e1936a6a64ca4971eeeea57 (patch) | |
tree | d8208496bbc8d80f614f02998580007b34a987d0 /src/event/EventPipe.cxx | |
parent | b70d38dc10868a7ddfac2df7001be36fc37fc21c (diff) | |
download | mpd-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/EventPipe.cxx | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/src/event/EventPipe.cxx b/src/event/EventPipe.cxx index 3b52118e4..e1a38c503 100644 --- a/src/event/EventPipe.cxx +++ b/src/event/EventPipe.cxx @@ -20,8 +20,10 @@ #include "config.h" #include "EventPipe.hxx" #include "system/fd_util.h" +#include "system/FatalError.hxx" #include "gcc.h" +#include <assert.h> #include <unistd.h> #ifdef WIN32 @@ -34,21 +36,18 @@ static bool PoorSocketPair(int fd[2]); #endif -bool -EventPipe::Create() +EventPipe::EventPipe() { - assert(fds[0] == -1); - assert(fds[1] == -1); - #ifdef WIN32 - return PoorSocketPair(fds); + bool success = PoorSocketPair(fds); #else - return pipe_cloexec_nonblock(fds) >= 0; + bool success = pipe_cloexec_nonblock(fds) >= 0; #endif + if (!success) + FatalSystemError("pipe() has failed"); } -void -EventPipe::Destroy() +EventPipe::~EventPipe() { #ifdef WIN32 closesocket(fds[0]); @@ -56,11 +55,6 @@ EventPipe::Destroy() #else close(fds[0]); close(fds[1]); - -#ifndef NDEBUG - fds[0] = -1; - fds[1] = -1; -#endif #endif } |