diff --git a/Packets/DefaultBundle/EthernetPacket.hh b/Packets/DefaultBundle/EthernetPacket.hh index ebb07ae5a8d03762078a41f12c18bc24cee91fc0..2bc9fb6054e9f66f9b02cc99de1f3203407d4dfb 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 <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 diff --git a/Packets/DefaultBundle/IpV4Packet.hh b/Packets/DefaultBundle/IpV4Packet.hh index 8bd7c699c20b32422a5508ded86020b271d34022..9d451c56402cdaee61a9c37d1448e5aa3e94a5ca 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 <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 { diff --git a/Socket/FileHandle.ih b/Socket/FileHandle.ih index 380b39f484c9d93b46db078b88175c1ebae55e0f..acde0153b661caa5b6e96a8361e1fa88c6a9871d 100644 --- a/Socket/FileHandle.ih +++ b/Socket/FileHandle.ih @@ -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: /////////////////////////////////////////////////////////////////////////// diff --git a/Socket/PacketSocketHandle.hh b/Socket/PacketSocketHandle.hh index a435369ba82b9120e95fdc7818f738e92e229631..82824763ce7e4272e130145290643777b1738631 100644 --- a/Socket/PacketSocketHandle.hh +++ b/Socket/PacketSocketHandle.hh @@ -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 }; diff --git a/Socket/SocketHandle.ih b/Socket/SocketHandle.ih index 5bef63a659625b82729f1a853f8d77abf506d4ed..5e9fae41cf89c3098647aab466e605d41db62b03 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<SocketBody> { public: + using senf::pool_alloc_mixin<SocketBody>::operator new; + using senf::pool_alloc_mixin<SocketBody>::operator delete; + /////////////////////////////////////////////////////////////////////////// // Types diff --git a/Socket/SocketPolicy.ih b/Socket/SocketPolicy.ih index 09ccc391956c2a23a4daf753cd902bef6a90d5dc..6d41c691993c3aa5b9b8c1c38dab2b56a9a34f84 100644 --- a/Socket/SocketPolicy.ih +++ b/Socket/SocketPolicy.ih @@ -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 ) diff --git a/Socket/SocketProtocol.hh b/Socket/SocketProtocol.hh index c829647441f050e79bf9fd7a69c4376b30e296b1..206f7ccf29cd0a804f26683cc204e7c4a257b78c 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 c4c6c94f863011dd7bfd70a7fb48ab59f44ea0ad..2e00ee513aed1f93e58786275baef9975c3c52e2 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<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: /////////////////////////////////////////////////////////////////////////// diff --git a/Socket/UDPSocketHandle.hh b/Socket/UDPSocketHandle.hh index 62362b4bcad9c56864e4fc4cf113e844722e8199..f10d96011b7676ee7328071bfa43d4d42274967d 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<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: /////////////////////////////////////////////////////////////////////////// diff --git a/Utils/pool_alloc_mixin.cti b/Utils/pool_alloc_mixin.cti index a16314638c66e80dfcd8358aaf895a5f084f8abe..8bb0eef5096c77c03d4469b52f8644ce334438b2 100644 --- a/Utils/pool_alloc_mixin.cti +++ b/Utils/pool_alloc_mixin.cti @@ -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 diff --git a/senf.dict b/senf.dict index d3b22f4b22be1a73d07d579c59f2115732ed26b4..973468e4d95b2cab4203b43ee9b38b7e56ace418 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