summaryrefslogtreecommitdiff
path: root/lib/Handle.cc
diff options
context:
space:
mode:
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;
+}