Socket: Add senf::pool_alloc_mixin to most socket classes
g0dil [Tue, 24 Jul 2007 13:34:53 +0000 (13:34 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@347 270642c3-0616-0410-b53a-bc976706d245

Packets/DefaultBundle/EthernetPacket.hh
Packets/DefaultBundle/IpV4Packet.hh
Socket/FileHandle.ih
Socket/PacketSocketHandle.hh
Socket/SocketHandle.ih
Socket/SocketPolicy.ih
Socket/SocketProtocol.hh
Socket/TCPSocketHandle.hh
Socket/UDPSocketHandle.hh
Utils/pool_alloc_mixin.cti
senf.dict

index ebb07ae..2bc9fb6 100644 (file)
@@ -106,8 +106,8 @@ namespace senf {
 
         This registry registers packet types with their EtherType number.
         
-        \see <a href="http://www.iana.org/assignments/ethernet-numbers">Ethernet numbers</a>
-         \ref PacketRegistry
+        \see <a href="http://www.iana.org/assignments/ethernet-numbers">Ethernet numbers</a> \n
+            \ref PacketRegistry
      */
     struct EtherTypes {
         // See 
index 8bd7c69..9d451c5 100644 (file)
@@ -100,7 +100,7 @@ namespace senf {
 
         This registeres packets with their IP protocol number.
 
-        \see <a href="http://www.iana.org/assignments/protocol-numbers">Protocol numbers</a>
+        \see <a href="http://www.iana.org/assignments/protocol-numbers">Protocol numbers</a> \n
             PacketRegistry
      */
     struct IpTypes {
index 380b39f..acde015 100644 (file)
@@ -30,6 +30,7 @@
 // Custom includes
 #include <boost/intrusive_ptr.hpp>
 #include "Utils/intrusive_refcount.hh"
+#include "Utils/pool_alloc_mixin.hh"
 
 ///////////////////////////////ih.p////////////////////////////////////////
 
@@ -40,7 +41,7 @@ namespace senf {
 
         \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.
 
@@ -59,9 +60,12 @@ namespace senf {
         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:
         ///////////////////////////////////////////////////////////////////////////
index a435369..8282476 100644 (file)
@@ -80,7 +80,8 @@ namespace senf {
      */
     class PacketProtocol
         : public ConcreteSocketProtocol<Packet_Policy>,
-          public BSDSocketProtocol
+          public BSDSocketProtocol,
+          public senf::pool_alloc_mixin<PacketProtocol>
     {
     public:
         enum SocketType { RawSocket, DatagramSocket };
index 5bef63a..5e9fae4 100644 (file)
@@ -101,9 +101,13 @@ namespace senf {
         properly. If this invariant is violated, your Program will probably crash.
      */
     class SocketBody
-        : public FileBody
+        : public FileBody, 
+          public senf::pool_alloc_mixin<SocketBody>
     {
     public:
+        using senf::pool_alloc_mixin<SocketBody>::operator new;
+        using senf::pool_alloc_mixin<SocketBody>::operator delete;
+
         ///////////////////////////////////////////////////////////////////////////
         // Types
 
index 09ccc39..6d41c69 100644 (file)
@@ -50,6 +50,8 @@
 #include <boost/mpl/and.hpp>
 #include <boost/utility.hpp> // for enable_if
 
+#include "Utils/pool_alloc_mixin.hh"
+
 ///////////////////////////////ih.p////////////////////////////////////////
 
 /// \cond disabled
@@ -59,7 +61,7 @@ namespace senf {
 
 #   define SENF_SOCKET_POLICIES_N BOOST_PP_SEQ_SIZE( SENF_SOCKET_POLICIES )
 
-#   define SP_DeclareAlias(x1,x2,SomePolicy)                                             \
+#   define SP_DeclareAlias(x1,x2,SomePolicy)                                                      \
         typedef BOOST_PP_CAT(SomePolicy,Base) BOOST_PP_CAT(Unspecified,SomePolicy);
 
     BOOST_PP_SEQ_FOR_EACH( SP_DeclareAlias, , SENF_SOCKET_POLICIES )
@@ -70,26 +72,31 @@ namespace senf {
     {
         virtual ~SocketPolicyBase() {}
 
-#       define SP_Declare(x1,x2,SomePolicy)                                                     \
-            virtual BOOST_PP_CAT(SomePolicy,Base) const & BOOST_PP_CAT(the,SomePolicy) () const = 0;
+#       define SP_Declare(x1,x2,SomePolicy)                                                       \
+            virtual BOOST_PP_CAT(SomePolicy,Base) const & BOOST_PP_CAT(the,SomePolicy) ()         \
+                const = 0;
 
         BOOST_PP_SEQ_FOR_EACH( SP_Declare, , SENF_SOCKET_POLICIES )
 
 #       undef SP_Declare
     };
 
-#   define SP_TemplateArgs(x1,x2,n,SomePolicy)                                  \
-        BOOST_PP_COMMA_IF( n )                                                  \
+#   define SP_TemplateArgs(x1,x2,n,SomePolicy)                                                    \
+        BOOST_PP_COMMA_IF( n )                                                                    \
         class BOOST_PP_CAT(SomePolicy,_) = BOOST_PP_CAT(SomePolicy,Base)
+#   define SP_TemplateParms(x1,x2,n,SomePolicy)                                                   \
+        BOOST_PP_COMMA_IF( n ) BOOST_PP_CAT(SomePolicy,_)
 
     template < BOOST_PP_SEQ_FOR_EACH_I( SP_TemplateArgs, , SENF_SOCKET_POLICIES ) >
     struct SocketPolicy
-        : public SocketPolicyBase
+        : public SocketPolicyBase,
+          public senf::pool_alloc_mixin< 
+              SocketPolicy< BOOST_PP_SEQ_FOR_EACH_I( SP_TemplateParms, , SENF_SOCKET_POLICIES ) > >
     {
-#   define SP_DeclarePolicyMember(x1,x2,SomePolicy)                                     \
-        typedef BOOST_PP_CAT(SomePolicy,_) SomePolicy;                                  \
-        SomePolicy BOOST_PP_CAT(BOOST_PP_CAT(the,SomePolicy),_);                        \
-        BOOST_PP_CAT(SomePolicy,Base) const & BOOST_PP_CAT(the,SomePolicy) () const     \
+#   define SP_DeclarePolicyMember(x1,x2,SomePolicy)                                               \
+        typedef BOOST_PP_CAT(SomePolicy,_) SomePolicy;                                            \
+        SomePolicy BOOST_PP_CAT(BOOST_PP_CAT(the,SomePolicy),_);                                  \
+        BOOST_PP_CAT(SomePolicy,Base) const & BOOST_PP_CAT(the,SomePolicy) () const               \
             { return BOOST_PP_CAT(BOOST_PP_CAT(the,SomePolicy),_); }
 
         BOOST_PP_SEQ_FOR_EACH( SP_DeclarePolicyMember, , SENF_SOCKET_POLICIES )
@@ -99,6 +106,7 @@ namespace senf {
     };
 
 #   undef SP_TemplateArgs
+#   undef SP_TemplateParms
 
 namespace impl {
 
@@ -112,20 +120,23 @@ namespace impl {
     struct MakeSocketPolicy_merge
     {};
 
-#   define SP_DeclareMakeSocketPolicy_merge_member(r,n,m,SomePolicy)            \
-        BOOST_PP_COMMA_IF( m )                                                  \
+#   define SP_DeclareMakeSocketPolicy_merge_member(r,n,m,SomePolicy)                              \
+        BOOST_PP_COMMA_IF( m )                                                                    \
         BOOST_PP_IIF( BOOST_PP_EQUAL(n,m), Policy, typename Base::SomePolicy )
 
 #    define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_DEC( SENF_SOCKET_POLICIES_N ) )
-#    define BOOST_PP_LOCAL_MACRO(n)                                                                                     \
-        SocketPolicy_rv<n> MakeSocketPolicy_merge_(BOOST_PP_CAT( BOOST_PP_SEQ_ELEM( n, SENF_SOCKET_POLICIES ),Base)*);  \
-                                                                                                                        \
-        template <class Base, class Policy>                                                                             \
-        struct MakeSocketPolicy_merge<Base,Policy,sizeof(SocketPolicy_rv<n>)>                                           \
-        {                                                                                                               \
-            typedef SocketPolicy<                                                                                       \
-               BOOST_PP_SEQ_FOR_EACH_I( SP_DeclareMakeSocketPolicy_merge_member, n, SENF_SOCKET_POLICIES )              \
-               > type;                                                                                                  \
+#    define BOOST_PP_LOCAL_MACRO(n)                                                               \
+        SocketPolicy_rv<n> MakeSocketPolicy_merge_(                                               \
+            BOOST_PP_CAT( BOOST_PP_SEQ_ELEM( n, SENF_SOCKET_POLICIES ),Base)*);                   \
+                                                                                                  \
+        template <class Base, class Policy>                                                       \
+        struct MakeSocketPolicy_merge<Base,Policy,sizeof(SocketPolicy_rv<n>)>                     \
+        {                                                                                         \
+            typedef SocketPolicy<                                                                 \
+               BOOST_PP_SEQ_FOR_EACH_I( SP_DeclareMakeSocketPolicy_merge_member,                  \
+                                        n,                                                        \
+                                        SENF_SOCKET_POLICIES )                                    \
+               > type;                                                                            \
         };
 
 #   include BOOST_PP_LOCAL_ITERATE()
@@ -154,8 +165,8 @@ namespace impl {
         typedef typename boost::mpl::fold< Vector, Base, MakeSocketPolicy_fold >::type policy;
     };
 
-#   define SP_DeclareArguments(x1,x2,n,SomePolicy)      \
-        BOOST_PP_COMMA_IF( n )                          \
+#   define SP_DeclareArguments(x1,x2,n,SomePolicy)                                                \
+        BOOST_PP_COMMA_IF( n )                                                                    \
         typename Base::SomePolicy *
 
     template <class Base>
@@ -178,8 +189,8 @@ namespace impl {
     {};
 
 
-#   define SP_DeclareArguments(x1,x2,n,SomePolicy)      \
-        BOOST_PP_COMMA_IF( n )                          \
+#   define SP_DeclareArguments(x1,x2,n,SomePolicy)                                                \
+        BOOST_PP_COMMA_IF( n )                                                                    \
         static_cast<typename Derived::SomePolicy *>(0)
 
     template <class Base, class Derived>
@@ -191,36 +202,47 @@ namespace impl {
 
 } // namespace impl
 
-    template < BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT( SENF_SOCKET_POLICIES_N, class T, senf::impl::nil ) >
+    template < BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT( SENF_SOCKET_POLICIES_N, 
+                                                    class T, 
+                                                    senf::impl::nil ) >
     class MakeSocketPolicy
         : public boost::mpl::if_< boost::is_convertible< T0*, SocketPolicyBase* >,
-                                  impl::MakeSocketPolicy_impl< T0, boost::mpl::vector< BOOST_PP_ENUM_SHIFTED_PARAMS( SENF_SOCKET_POLICIES_N, T ) > >,
-                                  impl::MakeSocketPolicy_impl< SocketPolicy<>,
-                                                               boost::mpl::vector< BOOST_PP_ENUM_PARAMS( SENF_SOCKET_POLICIES_N, T ) > > >::type
+                                  impl::MakeSocketPolicy_impl< 
+                                      T0, 
+                                      boost::mpl::vector< 
+                                          BOOST_PP_ENUM_SHIFTED_PARAMS( 
+                                              SENF_SOCKET_POLICIES_N, T ) > >,
+                                  impl::MakeSocketPolicy_impl< 
+                                      SocketPolicy<>,
+                                      boost::mpl::vector< 
+                                          BOOST_PP_ENUM_PARAMS( 
+                                              SENF_SOCKET_POLICIES_N, T ) > > >::type
     {};
 
     template <class BasePolicy, class DerivedPolicy>
     struct SocketPolicyIsBaseOf
-        : public boost::mpl::if_< boost::mpl::and_< boost::is_convertible< BasePolicy*, SocketPolicyBase* >,
-                                                    boost::is_convertible< DerivedPolicy*, SocketPolicyBase* > >,
-                                  impl::SocketPolicy_compatibility<BasePolicy,DerivedPolicy>,
-                                  boost::false_type >::type
+        : public boost::mpl::if_< 
+              boost::mpl::and_< boost::is_convertible< BasePolicy*, SocketPolicyBase* >,
+                                boost::is_convertible< DerivedPolicy*, SocketPolicyBase* > >,
+              impl::SocketPolicy_compatibility<BasePolicy,DerivedPolicy>,
+              boost::false_type 
+          >::type
     {};
 
-#   define SP_DefineConditions(x1,x2,SomePolicy)                                                \
-        template <class Policy, class Trait>                                                    \
-        struct BOOST_PP_CAT(SomePolicy,Is)                                                      \
-            : public boost::is_convertible< typename Policy::SomePolicy*, Trait* >              \
-        {};                                                                                     \
-                                                                                                \
-        template <class Policy, class Trait>                                                    \
-        struct BOOST_PP_CAT(BOOST_PP_CAT(If,SomePolicy),Is)                                     \
-            : public boost::enable_if< BOOST_PP_CAT(SomePolicy,Is)<Policy,Trait> >              \
-        {};                                                                                     \
-                                                                                                \
-        template <class Policy, class Trait>                                                    \
-        struct BOOST_PP_CAT(BOOST_PP_CAT(If,SomePolicy),IsNot)                                  \
-            : public boost::enable_if_c< ! BOOST_PP_CAT(SomePolicy,Is)<Policy,Trait>::value >   \
+#   define SP_DefineConditions(x1,x2,SomePolicy)                                                  \
+        template <class Policy, class Trait>                                                      \
+        struct BOOST_PP_CAT(SomePolicy,Is)                                                        \
+            : public boost::is_convertible< typename Policy::SomePolicy*, Trait* >                \
+        {};                                                                                       \
+                                                                                                  \
+        template <class Policy, class Trait>                                                      \
+        struct BOOST_PP_CAT(BOOST_PP_CAT(If,SomePolicy),Is)                                       \
+            : public boost::enable_if< BOOST_PP_CAT(SomePolicy,Is)<Policy,Trait> >                \
+        {};                                                                                       \
+                                                                                                  \
+        template <class Policy, class Trait>                                                      \
+        struct BOOST_PP_CAT(BOOST_PP_CAT(If,SomePolicy),IsNot)                                    \
+            : public boost::enable_if_c< ! BOOST_PP_CAT(SomePolicy,Is)<Policy,Trait>::value >     \
         {};
 
     BOOST_PP_SEQ_FOR_EACH( SP_DefineConditions, , SENF_SOCKET_POLICIES )
index c829647..206f7cc 100644 (file)
@@ -65,9 +65,9 @@
     protocols are implemented using a simple multiple-inheritance hierarchy as shown above.
 
     Since the protocol class is protocol specific (how intelligent ...), the protocol class also
-    defines the complete socket policy to be used with it's protocol. Complete meaning, that every
-    policy axis must be assigned it's the most specific (that is derived) policy class to be used
-    with the protocol.
+    defines the \e complete socket policy to be used with it's protocol. Complete meaning, that
+    every policy axis must be assigned it's the most specific (that is derived) policy class to be
+    used with the protocol and that no policy axis is allowed to be left unspecified.
 
     \see
         \ref handle_group \n
@@ -126,7 +126,8 @@ namespace senf {
 
         \attention SocketProtocol must \e always be inherited using public \e virtual inheritance.
      */
-    class SocketProtocol : boost::noncopyable
+    class SocketProtocol 
+        : boost::noncopyable
     {
     public:
         ///////////////////////////////////////////////////////////////////////////
index c4c6c94..2e00ee5 100644 (file)
@@ -31,6 +31,7 @@
 #define HH_TCPSocketHandle_ 1
 
 // Custom includes
+#include "Utils/pool_alloc_mixin.hh"
 #include "INetProtocol.hh"
 #include "TCPProtocol.hh"
 #include "BSDSocketProtocol.hh"
@@ -85,7 +86,8 @@ namespace senf {
           public IPv4Protocol,
           public TCPProtocol,
           public BSDSocketProtocol,
-          public AddressableBSDSocketProtocol
+          public AddressableBSDSocketProtocol,
+          public senf::pool_alloc_mixin<TCPv4SocketProtocol>
     {
     public:
         ///////////////////////////////////////////////////////////////////////////
@@ -166,7 +168,8 @@ namespace senf {
           public IPv6Protocol,
           public TCPProtocol,
           public BSDSocketProtocol,
-          public AddressableBSDSocketProtocol
+          public AddressableBSDSocketProtocol,
+          public senf::pool_alloc_mixin<TCPv6SocketProtocol>
     {
     public:
         ///////////////////////////////////////////////////////////////////////////
index 62362b4..f10d960 100644 (file)
@@ -83,7 +83,8 @@ namespace senf {
           public IPv4Protocol,
           public UDPProtocol,
           public BSDSocketProtocol,
-          public AddressableBSDSocketProtocol
+          public AddressableBSDSocketProtocol,
+          public senf::pool_alloc_mixin<UDPv4SocketProtocol>
     {
     public:
         ///////////////////////////////////////////////////////////////////////////
@@ -147,7 +148,8 @@ namespace senf {
           public IPv6Protocol,
           public UDPProtocol,
           public BSDSocketProtocol,
-          public AddressableBSDSocketProtocol
+          public AddressableBSDSocketProtocol,
+          public senf::pool_alloc_mixin<UDPv6SocketProtocol>
     {
     public:
         ///////////////////////////////////////////////////////////////////////////
index a163146..8bb0eef 100644 (file)
@@ -34,7 +34,7 @@ prefix_ void * senf::pool_alloc_mixin<Self>::operator new(size_t size)
 {
     // When deriving from Self you may not change the class's size without
     // inheriting from pool_alloc_mixin again. See pool_alloc_mixin documentation.
-    BOOST_ASSERT( size == sizeof(Self) );
+    BOOST_ASSERT( size <= sizeof(Self) );
 #ifndef NDEBUG
     allocCounter(1);
 #endif
index d3b22f4..973468e 100644 (file)
--- a/senf.dict
+++ b/senf.dict
@@ -1,6 +1,7 @@
 accessor
 addtogroup
 aListCollection
+alloc
 aVectorCollection
 BaseParser
 berlios
@@ -22,6 +23,7 @@ dil
 dontinclude
 ElementParser
 endcode
+eof
 eth
 ethernet
 EthernetPacket
@@ -32,6 +34,9 @@ EthVLan
 ExampleListPolicy
 ExampleVectorPolicy
 ExtendedParser
+FileBody
+filebody
+FileHandle
 findNext
 findPrev
 fokus
@@ -145,6 +150,7 @@ stefan
 STL
 struct
 structors
+SystemException
 templated
 todo
 TruncatedPacketException