From: g0dil Date: Tue, 24 Jul 2007 13:34:53 +0000 (+0000) Subject: Socket: Add senf::pool_alloc_mixin to most socket classes X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=3d5b1045dc2531f239a3af4a8f3b17b1fe31549c;p=senf.git Socket: Add senf::pool_alloc_mixin to most socket classes git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@347 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Packets/DefaultBundle/EthernetPacket.hh b/Packets/DefaultBundle/EthernetPacket.hh index ebb07ae..2bc9fb6 100644 --- a/Packets/DefaultBundle/EthernetPacket.hh +++ b/Packets/DefaultBundle/EthernetPacket.hh @@ -106,8 +106,8 @@ namespace senf { This registry registers packet types with their EtherType number. - \see Ethernet numbers - \ref PacketRegistry + \see Ethernet numbers \n + \ref PacketRegistry */ struct EtherTypes { // See diff --git a/Packets/DefaultBundle/IpV4Packet.hh b/Packets/DefaultBundle/IpV4Packet.hh index 8bd7c69..9d451c5 100644 --- a/Packets/DefaultBundle/IpV4Packet.hh +++ b/Packets/DefaultBundle/IpV4Packet.hh @@ -100,7 +100,7 @@ namespace senf { This registeres packets with their IP protocol number. - \see Protocol numbers + \see Protocol numbers \n PacketRegistry */ struct IpTypes { diff --git a/Socket/FileHandle.ih b/Socket/FileHandle.ih index 380b39f..acde015 100644 --- a/Socket/FileHandle.ih +++ b/Socket/FileHandle.ih @@ -30,6 +30,7 @@ // Custom includes #include #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 { public: /////////////////////////////////////////////////////////////////////////// diff --git a/Socket/PacketSocketHandle.hh b/Socket/PacketSocketHandle.hh index a435369..8282476 100644 --- a/Socket/PacketSocketHandle.hh +++ b/Socket/PacketSocketHandle.hh @@ -80,7 +80,8 @@ namespace senf { */ class PacketProtocol : public ConcreteSocketProtocol, - public BSDSocketProtocol + public BSDSocketProtocol, + public senf::pool_alloc_mixin { public: enum SocketType { RawSocket, DatagramSocket }; diff --git a/Socket/SocketHandle.ih b/Socket/SocketHandle.ih index 5bef63a..5e9fae4 100644 --- a/Socket/SocketHandle.ih +++ b/Socket/SocketHandle.ih @@ -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 { public: + using senf::pool_alloc_mixin::operator new; + using senf::pool_alloc_mixin::operator delete; + /////////////////////////////////////////////////////////////////////////// // Types diff --git a/Socket/SocketPolicy.ih b/Socket/SocketPolicy.ih index 09ccc39..6d41c69 100644 --- a/Socket/SocketPolicy.ih +++ b/Socket/SocketPolicy.ih @@ -50,6 +50,8 @@ #include #include // 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 MakeSocketPolicy_merge_(BOOST_PP_CAT( BOOST_PP_SEQ_ELEM( n, SENF_SOCKET_POLICIES ),Base)*); \ - \ - template \ - struct MakeSocketPolicy_merge)> \ - { \ - 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 MakeSocketPolicy_merge_( \ + BOOST_PP_CAT( BOOST_PP_SEQ_ELEM( n, SENF_SOCKET_POLICIES ),Base)*); \ + \ + template \ + struct MakeSocketPolicy_merge)> \ + { \ + 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 @@ -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(0) template @@ -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 struct SocketPolicyIsBaseOf - : public boost::mpl::if_< boost::mpl::and_< boost::is_convertible< BasePolicy*, SocketPolicyBase* >, - boost::is_convertible< DerivedPolicy*, SocketPolicyBase* > >, - impl::SocketPolicy_compatibility, - boost::false_type >::type + : public boost::mpl::if_< + boost::mpl::and_< boost::is_convertible< BasePolicy*, SocketPolicyBase* >, + boost::is_convertible< DerivedPolicy*, SocketPolicyBase* > >, + impl::SocketPolicy_compatibility, + boost::false_type + >::type {}; -# define SP_DefineConditions(x1,x2,SomePolicy) \ - template \ - struct BOOST_PP_CAT(SomePolicy,Is) \ - : public boost::is_convertible< typename Policy::SomePolicy*, Trait* > \ - {}; \ - \ - template \ - struct BOOST_PP_CAT(BOOST_PP_CAT(If,SomePolicy),Is) \ - : public boost::enable_if< BOOST_PP_CAT(SomePolicy,Is) > \ - {}; \ - \ - template \ - struct BOOST_PP_CAT(BOOST_PP_CAT(If,SomePolicy),IsNot) \ - : public boost::enable_if_c< ! BOOST_PP_CAT(SomePolicy,Is)::value > \ +# define SP_DefineConditions(x1,x2,SomePolicy) \ + template \ + struct BOOST_PP_CAT(SomePolicy,Is) \ + : public boost::is_convertible< typename Policy::SomePolicy*, Trait* > \ + {}; \ + \ + template \ + struct BOOST_PP_CAT(BOOST_PP_CAT(If,SomePolicy),Is) \ + : public boost::enable_if< BOOST_PP_CAT(SomePolicy,Is) > \ + {}; \ + \ + template \ + struct BOOST_PP_CAT(BOOST_PP_CAT(If,SomePolicy),IsNot) \ + : public boost::enable_if_c< ! BOOST_PP_CAT(SomePolicy,Is)::value > \ {}; BOOST_PP_SEQ_FOR_EACH( SP_DefineConditions, , SENF_SOCKET_POLICIES ) diff --git a/Socket/SocketProtocol.hh b/Socket/SocketProtocol.hh index c829647..206f7cc 100644 --- a/Socket/SocketProtocol.hh +++ b/Socket/SocketProtocol.hh @@ -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: /////////////////////////////////////////////////////////////////////////// diff --git a/Socket/TCPSocketHandle.hh b/Socket/TCPSocketHandle.hh index c4c6c94..2e00ee5 100644 --- a/Socket/TCPSocketHandle.hh +++ b/Socket/TCPSocketHandle.hh @@ -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 { public: /////////////////////////////////////////////////////////////////////////// @@ -166,7 +168,8 @@ namespace senf { public IPv6Protocol, public TCPProtocol, public BSDSocketProtocol, - public AddressableBSDSocketProtocol + public AddressableBSDSocketProtocol, + public senf::pool_alloc_mixin { public: /////////////////////////////////////////////////////////////////////////// diff --git a/Socket/UDPSocketHandle.hh b/Socket/UDPSocketHandle.hh index 62362b4..f10d960 100644 --- a/Socket/UDPSocketHandle.hh +++ b/Socket/UDPSocketHandle.hh @@ -83,7 +83,8 @@ namespace senf { public IPv4Protocol, public UDPProtocol, public BSDSocketProtocol, - public AddressableBSDSocketProtocol + public AddressableBSDSocketProtocol, + public senf::pool_alloc_mixin { public: /////////////////////////////////////////////////////////////////////////// @@ -147,7 +148,8 @@ namespace senf { public IPv6Protocol, public UDPProtocol, public BSDSocketProtocol, - public AddressableBSDSocketProtocol + public AddressableBSDSocketProtocol, + public senf::pool_alloc_mixin { public: /////////////////////////////////////////////////////////////////////////// diff --git a/Utils/pool_alloc_mixin.cti b/Utils/pool_alloc_mixin.cti index a163146..8bb0eef 100644 --- a/Utils/pool_alloc_mixin.cti +++ b/Utils/pool_alloc_mixin.cti @@ -34,7 +34,7 @@ prefix_ void * senf::pool_alloc_mixin::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 diff --git a/senf.dict b/senf.dict index d3b22f4..973468e 100644 --- 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