summaryrefslogtreecommitdiff
path: root/p2pvr/lib/fileHandle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'p2pvr/lib/fileHandle.cpp')
-rw-r--r--p2pvr/lib/fileHandle.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/p2pvr/lib/fileHandle.cpp b/p2pvr/lib/fileHandle.cpp
new file mode 100644
index 0000000..08575b3
--- /dev/null
+++ b/p2pvr/lib/fileHandle.cpp
@@ -0,0 +1,27 @@
+#include "fileHandle.h"
+#include <unistd.h>
+#include <stdexcept>
+
+class InvalidFileHandle : public std::runtime_error {
+ public:
+ InvalidFileHandle() : std::runtime_error("Invalid file handle") { }
+};
+
+FileHandle::FileHandle(int f) :
+ fd(f)
+{
+ if (fd < 0) {
+ throw InvalidFileHandle();
+ }
+}
+
+FileHandle::~FileHandle()
+{
+ close(fd);
+}
+
+FileHandle::operator int() const
+{
+ return fd;
+}
+