summaryrefslogtreecommitdiff
path: root/lib/Handle.cc
diff options
context:
space:
mode:
authorPixel <Pixel>2001-10-29 15:44:12 +0000
committerPixel <Pixel>2001-10-29 15:44:12 +0000
commit2e5bed84841f33ff28dd95b77b555720c875a286 (patch)
treede6cbcbf5fa65e90e1888d52a9426373a1638c61 /lib/Handle.cc
parent0a6190d0269392e875a479df01b152d47ea4143c (diff)
Beginning task manager
Diffstat (limited to 'lib/Handle.cc')
-rw-r--r--lib/Handle.cc24
1 files changed, 19 insertions, 5 deletions
diff --git a/lib/Handle.cc b/lib/Handle.cc
index 4824b43..c3efc55 100644
--- a/lib/Handle.cc
+++ b/lib/Handle.cc
@@ -6,11 +6,11 @@
#include "Handle.h"
#include "config.h"
-Handle::Handle(const Handle & nh) : h(dup(nh.h)), closed(false), nonblock(false) { }
+Handle::Handle(const Handle & nh) : h(nh.h >= 0 ? dup(nh.h) : nh.h), closed(false), nonblock(false) { }
Handle::~Handle() {
- if (h != -1) {
- close(h);
+ if (h >= 0) {
+ ::close(h);
}
}
@@ -73,7 +73,7 @@ ssize_t Handle::read(void *buf, size_t count) throw (IOException) {
}
if (!r) {
- close(h);
+ ::close(h);
closed = true;
}
@@ -90,7 +90,9 @@ bool Handle::IsNonBlock(void) {
void Handle::SetNonBlock(void) {
nonblock = true;
- fcntl(h, F_SETFL, O_NONBLOCK);
+ if (h >= 0) {
+ fcntl(h, F_SETFL, O_NONBLOCK);
+ }
}
Handle & operator<<(Handle & h, const String & s) {
@@ -124,3 +126,15 @@ Handle & operator>>(Handle & h, String & s) {
s.set("%s", t);
return h;
}
+
+void Handle::close() {
+ if (IsClosed()) {
+ return;
+ }
+
+ if (h >= 0) {
+ ::close(h);
+ }
+
+ closed = 1;
+}