Socket: BUGFIX: Move incorrect v-function call out of FileBody destructor
[senf.git] / Socket / FileHandle.cci
index 4ace14c..79308ae 100644 (file)
@@ -1,8 +1,8 @@
 // $Id$
 //
 // Copyright (C) 2006
-// Fraunhofer Institute for Open Communication Systems (FOKUS) 
-// Competence Center NETwork research (NET), St. Augustin, GERMANY 
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
 //     Stefan Bund <g0dil@berlios.de>
 //
 // This program is free software; you can redistribute it and/or modify
@@ -41,33 +41,6 @@ prefix_ senf::FileBody::FileBody(int fd)
     : fd_(fd)
 {}
 
-prefix_  senf::FileBody::~FileBody()
-{
-    if (valid())
-        try {
-            close();
-        }
-        catch (...) {
-            terminate();
-        }
-}
-
-prefix_ void senf::FileBody::close()
-{
-    if (!valid())
-        throwErrno(EBADF);
-    v_close();
-    fd_ = -1;
-}
-
-prefix_ void senf::FileBody::terminate()
-{
-    if (valid()) {
-        v_terminate();
-        fd_ = -1;
-    }
-}
-
 prefix_ senf::FileHandle senf::FileBody::handle()
 {
     return FileHandle(ptr(this));
@@ -196,6 +169,12 @@ prefix_ senf::FileHandle::FileHandle()
     : body_(0)
 {}
 
+prefix_ senf::FileHandle::~FileHandle()
+{
+    if (body_ && ! body().is_shared())
+        body().destroyClose();
+}
+
 prefix_  senf::FileHandle::FileHandle(std::auto_ptr<FileBody> body)
     : body_(body.release())
 {}