Socket: BUGFIX: Move incorrect v-function call out of FileBody destructor
[senf.git] / Socket / FileHandle.ih
index 25b45c7..e87e319 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 //
 // Copyright (C) 2006
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-//     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
+// 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
 // it under the terms of the GNU General Public License as published by
 
 // Custom includes
 #include <boost/intrusive_ptr.hpp>
-#include "Utils/intrusive_refcount.hh"
+#include "../Utils/intrusive_refcount.hh"
+#include "../Utils/pool_alloc_mixin.hh"
 
 ///////////////////////////////ih.p////////////////////////////////////////
 
 namespace senf {
 
+    class FileHandle;
 
     /** \brief FileHandle referenced body
 
         \internal
 
-        The senf::FileBody class formes the body part of the handle/body structure of the FileHandle
+        The senf::FileBody class forms the body part of the handle/body structure of the FileHandle
         interface. It manages the FileHandle data and is referenced by senf::FileHandle. It is
         automatically managed using reference counting.
 
@@ -56,12 +58,15 @@ namespace senf {
         pointing to a different body type).
 
         To customize the behavior, a virtual interface is provided. This interface only covers some
-        basic funcionality which is only used infrequently during the lifetime of a FileHandle
+        basic functionality which is only used infrequently during the lifetime of a FileHandle
         instance.
 
+        \attention Whenever a new class is derived from FileBody which adds new members, this class
+            \e must also derive from senf::pool_alloc_mixin
       */
     class FileBody
-        : public senf::intrusive_refcount
+        : public senf::intrusive_refcount, 
+          public senf::pool_alloc_mixin<FileBody>
     {
     public:
         ///////////////////////////////////////////////////////////////////////////
@@ -78,7 +83,10 @@ namespace senf {
                                            constructor not some arbitrary id even if you overload
                                            all the virtual members. If the file descriptor is -1 the
                                            resulting body/handle is not valid() */
-        virtual ~FileBody();
+
+        // NO DESTRUCTOR HERE - destructors and virtual functions don't mix. What would be in the
+        // the destructor is in 'destroyClose()' which is called from FileHandle::~FileHandle()
+        // *before* the last handle dies.
 
         // no copy
         // no conversion constructors
@@ -86,11 +94,14 @@ namespace senf {
         ///@}
         ///////////////////////////////////////////////////////////////////////////
 
+        FileHandle handle();
+
         int fd() const;
         void fd(int fd);
 
         void close();
         void terminate();
+        void destroyClose();
 
         bool readable() const;
         void waitReadable() const;
@@ -145,4 +156,6 @@ namespace senf {
 // c-file-style: "senf"
 // indent-tabs-mode: nil
 // ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
 // End: