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.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/p2pvr/lib/fileHandle.cpp b/p2pvr/lib/fileHandle.cpp
new file mode 100644
index 0000000..b85d390
--- /dev/null
+++ b/p2pvr/lib/fileHandle.cpp
@@ -0,0 +1,28 @@
+#include <pch.hpp>
+#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;
+}
+