Skip to content
Snippets Groups Projects
Commit d3a1e774 authored by g0dil's avatar g0dil
Browse files

Socket: Add senf::pool_alloc_mixin to most socket classes

parent 010faaa0
No related branches found
No related tags found
No related merge requests found
...@@ -106,8 +106,8 @@ namespace senf { ...@@ -106,8 +106,8 @@ namespace senf {
This registry registers packet types with their EtherType number. This registry registers packet types with their EtherType number.
\see <a href="http://www.iana.org/assignments/ethernet-numbers">Ethernet numbers</a> \see <a href="http://www.iana.org/assignments/ethernet-numbers">Ethernet numbers</a> \n
\ref PacketRegistry \ref PacketRegistry
*/ */
struct EtherTypes { struct EtherTypes {
// See // See
......
...@@ -100,7 +100,7 @@ namespace senf { ...@@ -100,7 +100,7 @@ namespace senf {
This registeres packets with their IP protocol number. 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 PacketRegistry
*/ */
struct IpTypes { struct IpTypes {
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
// Custom includes // Custom includes
#include <boost/intrusive_ptr.hpp> #include <boost/intrusive_ptr.hpp>
#include "Utils/intrusive_refcount.hh" #include "Utils/intrusive_refcount.hh"
#include "Utils/pool_alloc_mixin.hh"
///////////////////////////////ih.p//////////////////////////////////////// ///////////////////////////////ih.p////////////////////////////////////////
...@@ -40,7 +41,7 @@ namespace senf { ...@@ -40,7 +41,7 @@ namespace senf {
\internal \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 interface. It manages the FileHandle data and is referenced by senf::FileHandle. It is
automatically managed using reference counting. automatically managed using reference counting.
...@@ -59,9 +60,12 @@ namespace senf { ...@@ -59,9 +60,12 @@ namespace senf {
basic functionality 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. 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 class FileBody
: public senf::intrusive_refcount : public senf::intrusive_refcount,
public senf::pool_alloc_mixin<FileBody>
{ {
public: public:
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
......
...@@ -80,7 +80,8 @@ namespace senf { ...@@ -80,7 +80,8 @@ namespace senf {
*/ */
class PacketProtocol class PacketProtocol
: public ConcreteSocketProtocol<Packet_Policy>, : public ConcreteSocketProtocol<Packet_Policy>,
public BSDSocketProtocol public BSDSocketProtocol,
public senf::pool_alloc_mixin<PacketProtocol>
{ {
public: public:
enum SocketType { RawSocket, DatagramSocket }; enum SocketType { RawSocket, DatagramSocket };
......
...@@ -101,9 +101,13 @@ namespace senf { ...@@ -101,9 +101,13 @@ namespace senf {
properly. If this invariant is violated, your Program will probably crash. properly. If this invariant is violated, your Program will probably crash.
*/ */
class SocketBody class SocketBody
: public FileBody : public FileBody,
public senf::pool_alloc_mixin<SocketBody>
{ {
public: public:
using senf::pool_alloc_mixin<SocketBody>::operator new;
using senf::pool_alloc_mixin<SocketBody>::operator delete;
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Types // Types
......
...@@ -50,6 +50,8 @@ ...@@ -50,6 +50,8 @@
#include <boost/mpl/and.hpp> #include <boost/mpl/and.hpp>
#include <boost/utility.hpp> // for enable_if #include <boost/utility.hpp> // for enable_if
#include "Utils/pool_alloc_mixin.hh"
///////////////////////////////ih.p//////////////////////////////////////// ///////////////////////////////ih.p////////////////////////////////////////
/// \cond disabled /// \cond disabled
...@@ -59,7 +61,7 @@ namespace senf { ...@@ -59,7 +61,7 @@ namespace senf {
# define SENF_SOCKET_POLICIES_N BOOST_PP_SEQ_SIZE( SENF_SOCKET_POLICIES ) # 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); typedef BOOST_PP_CAT(SomePolicy,Base) BOOST_PP_CAT(Unspecified,SomePolicy);
BOOST_PP_SEQ_FOR_EACH( SP_DeclareAlias, , SENF_SOCKET_POLICIES ) BOOST_PP_SEQ_FOR_EACH( SP_DeclareAlias, , SENF_SOCKET_POLICIES )
...@@ -70,26 +72,31 @@ namespace senf { ...@@ -70,26 +72,31 @@ namespace senf {
{ {
virtual ~SocketPolicyBase() {} virtual ~SocketPolicyBase() {}
# define SP_Declare(x1,x2,SomePolicy) \ # define SP_Declare(x1,x2,SomePolicy) \
virtual BOOST_PP_CAT(SomePolicy,Base) const & BOOST_PP_CAT(the,SomePolicy) () const = 0; virtual BOOST_PP_CAT(SomePolicy,Base) const & BOOST_PP_CAT(the,SomePolicy) () \
const = 0;
BOOST_PP_SEQ_FOR_EACH( SP_Declare, , SENF_SOCKET_POLICIES ) BOOST_PP_SEQ_FOR_EACH( SP_Declare, , SENF_SOCKET_POLICIES )
# undef SP_Declare # undef SP_Declare
}; };
# define SP_TemplateArgs(x1,x2,n,SomePolicy) \ # define SP_TemplateArgs(x1,x2,n,SomePolicy) \
BOOST_PP_COMMA_IF( n ) \ BOOST_PP_COMMA_IF( n ) \
class BOOST_PP_CAT(SomePolicy,_) = BOOST_PP_CAT(SomePolicy,Base) 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 ) > template < BOOST_PP_SEQ_FOR_EACH_I( SP_TemplateArgs, , SENF_SOCKET_POLICIES ) >
struct SocketPolicy 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) \ # define SP_DeclarePolicyMember(x1,x2,SomePolicy) \
typedef BOOST_PP_CAT(SomePolicy,_) SomePolicy; \ typedef BOOST_PP_CAT(SomePolicy,_) SomePolicy; \
SomePolicy BOOST_PP_CAT(BOOST_PP_CAT(the,SomePolicy),_); \ SomePolicy BOOST_PP_CAT(BOOST_PP_CAT(the,SomePolicy),_); \
BOOST_PP_CAT(SomePolicy,Base) const & BOOST_PP_CAT(the,SomePolicy) () const \ BOOST_PP_CAT(SomePolicy,Base) const & BOOST_PP_CAT(the,SomePolicy) () const \
{ return BOOST_PP_CAT(BOOST_PP_CAT(the,SomePolicy),_); } { return BOOST_PP_CAT(BOOST_PP_CAT(the,SomePolicy),_); }
BOOST_PP_SEQ_FOR_EACH( SP_DeclarePolicyMember, , SENF_SOCKET_POLICIES ) BOOST_PP_SEQ_FOR_EACH( SP_DeclarePolicyMember, , SENF_SOCKET_POLICIES )
...@@ -99,6 +106,7 @@ namespace senf { ...@@ -99,6 +106,7 @@ namespace senf {
}; };
# undef SP_TemplateArgs # undef SP_TemplateArgs
# undef SP_TemplateParms
namespace impl { namespace impl {
...@@ -112,20 +120,23 @@ namespace impl { ...@@ -112,20 +120,23 @@ namespace impl {
struct MakeSocketPolicy_merge struct MakeSocketPolicy_merge
{}; {};
# define SP_DeclareMakeSocketPolicy_merge_member(r,n,m,SomePolicy) \ # define SP_DeclareMakeSocketPolicy_merge_member(r,n,m,SomePolicy) \
BOOST_PP_COMMA_IF( m ) \ BOOST_PP_COMMA_IF( m ) \
BOOST_PP_IIF( BOOST_PP_EQUAL(n,m), Policy, typename Base::SomePolicy ) 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_LIMITS (0, BOOST_PP_DEC( SENF_SOCKET_POLICIES_N ) )
# define BOOST_PP_LOCAL_MACRO(n) \ # define BOOST_PP_LOCAL_MACRO(n) \
SocketPolicy_rv<n> MakeSocketPolicy_merge_(BOOST_PP_CAT( BOOST_PP_SEQ_ELEM( n, SENF_SOCKET_POLICIES ),Base)*); \ 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>)> \ 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 ) \ typedef SocketPolicy< \
> type; \ BOOST_PP_SEQ_FOR_EACH_I( SP_DeclareMakeSocketPolicy_merge_member, \
n, \
SENF_SOCKET_POLICIES ) \
> type; \
}; };
# include BOOST_PP_LOCAL_ITERATE() # include BOOST_PP_LOCAL_ITERATE()
...@@ -154,8 +165,8 @@ namespace impl { ...@@ -154,8 +165,8 @@ namespace impl {
typedef typename boost::mpl::fold< Vector, Base, MakeSocketPolicy_fold >::type policy; typedef typename boost::mpl::fold< Vector, Base, MakeSocketPolicy_fold >::type policy;
}; };
# define SP_DeclareArguments(x1,x2,n,SomePolicy) \ # define SP_DeclareArguments(x1,x2,n,SomePolicy) \
BOOST_PP_COMMA_IF( n ) \ BOOST_PP_COMMA_IF( n ) \
typename Base::SomePolicy * typename Base::SomePolicy *
template <class Base> template <class Base>
...@@ -178,8 +189,8 @@ namespace impl { ...@@ -178,8 +189,8 @@ namespace impl {
{}; {};
# define SP_DeclareArguments(x1,x2,n,SomePolicy) \ # define SP_DeclareArguments(x1,x2,n,SomePolicy) \
BOOST_PP_COMMA_IF( n ) \ BOOST_PP_COMMA_IF( n ) \
static_cast<typename Derived::SomePolicy *>(0) static_cast<typename Derived::SomePolicy *>(0)
template <class Base, class Derived> template <class Base, class Derived>
...@@ -191,36 +202,47 @@ namespace impl { ...@@ -191,36 +202,47 @@ namespace impl {
} // 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 class MakeSocketPolicy
: public boost::mpl::if_< boost::is_convertible< T0*, SocketPolicyBase* >, : 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<
impl::MakeSocketPolicy_impl< SocketPolicy<>, T0,
boost::mpl::vector< BOOST_PP_ENUM_PARAMS( SENF_SOCKET_POLICIES_N, T ) > > >::type 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> template <class BasePolicy, class DerivedPolicy>
struct SocketPolicyIsBaseOf struct SocketPolicyIsBaseOf
: public boost::mpl::if_< boost::mpl::and_< boost::is_convertible< BasePolicy*, SocketPolicyBase* >, : public boost::mpl::if_<
boost::is_convertible< DerivedPolicy*, SocketPolicyBase* > >, boost::mpl::and_< boost::is_convertible< BasePolicy*, SocketPolicyBase* >,
impl::SocketPolicy_compatibility<BasePolicy,DerivedPolicy>, boost::is_convertible< DerivedPolicy*, SocketPolicyBase* > >,
boost::false_type >::type impl::SocketPolicy_compatibility<BasePolicy,DerivedPolicy>,
boost::false_type
>::type
{}; {};
# define SP_DefineConditions(x1,x2,SomePolicy) \ # define SP_DefineConditions(x1,x2,SomePolicy) \
template <class Policy, class Trait> \ template <class Policy, class Trait> \
struct BOOST_PP_CAT(SomePolicy,Is) \ struct BOOST_PP_CAT(SomePolicy,Is) \
: public boost::is_convertible< typename Policy::SomePolicy*, Trait* > \ : public boost::is_convertible< typename Policy::SomePolicy*, Trait* > \
{}; \ {}; \
\ \
template <class Policy, class Trait> \ template <class Policy, class Trait> \
struct BOOST_PP_CAT(BOOST_PP_CAT(If,SomePolicy),Is) \ struct BOOST_PP_CAT(BOOST_PP_CAT(If,SomePolicy),Is) \
: public boost::enable_if< BOOST_PP_CAT(SomePolicy,Is)<Policy,Trait> > \ : public boost::enable_if< BOOST_PP_CAT(SomePolicy,Is)<Policy,Trait> > \
{}; \ {}; \
\ \
template <class Policy, class Trait> \ template <class Policy, class Trait> \
struct BOOST_PP_CAT(BOOST_PP_CAT(If,SomePolicy),IsNot) \ struct BOOST_PP_CAT(BOOST_PP_CAT(If,SomePolicy),IsNot) \
: public boost::enable_if_c< ! BOOST_PP_CAT(SomePolicy,Is)<Policy,Trait>::value > \ : public boost::enable_if_c< ! BOOST_PP_CAT(SomePolicy,Is)<Policy,Trait>::value > \
{}; {};
BOOST_PP_SEQ_FOR_EACH( SP_DefineConditions, , SENF_SOCKET_POLICIES ) BOOST_PP_SEQ_FOR_EACH( SP_DefineConditions, , SENF_SOCKET_POLICIES )
......
...@@ -65,9 +65,9 @@ ...@@ -65,9 +65,9 @@
protocols are implemented using a simple multiple-inheritance hierarchy as shown above. 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 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 defines the \e complete socket policy to be used with it's protocol. Complete meaning, that
policy axis must be assigned it's the most specific (that is derived) policy class to be used every policy axis must be assigned it's the most specific (that is derived) policy class to be
with the protocol. used with the protocol and that no policy axis is allowed to be left unspecified.
\see \see
\ref handle_group \n \ref handle_group \n
...@@ -126,7 +126,8 @@ namespace senf { ...@@ -126,7 +126,8 @@ namespace senf {
\attention SocketProtocol must \e always be inherited using public \e virtual inheritance. \attention SocketProtocol must \e always be inherited using public \e virtual inheritance.
*/ */
class SocketProtocol : boost::noncopyable class SocketProtocol
: boost::noncopyable
{ {
public: public:
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#define HH_TCPSocketHandle_ 1 #define HH_TCPSocketHandle_ 1
// Custom includes // Custom includes
#include "Utils/pool_alloc_mixin.hh"
#include "INetProtocol.hh" #include "INetProtocol.hh"
#include "TCPProtocol.hh" #include "TCPProtocol.hh"
#include "BSDSocketProtocol.hh" #include "BSDSocketProtocol.hh"
...@@ -85,7 +86,8 @@ namespace senf { ...@@ -85,7 +86,8 @@ namespace senf {
public IPv4Protocol, public IPv4Protocol,
public TCPProtocol, public TCPProtocol,
public BSDSocketProtocol, public BSDSocketProtocol,
public AddressableBSDSocketProtocol public AddressableBSDSocketProtocol,
public senf::pool_alloc_mixin<TCPv4SocketProtocol>
{ {
public: public:
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
...@@ -166,7 +168,8 @@ namespace senf { ...@@ -166,7 +168,8 @@ namespace senf {
public IPv6Protocol, public IPv6Protocol,
public TCPProtocol, public TCPProtocol,
public BSDSocketProtocol, public BSDSocketProtocol,
public AddressableBSDSocketProtocol public AddressableBSDSocketProtocol,
public senf::pool_alloc_mixin<TCPv6SocketProtocol>
{ {
public: public:
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
......
...@@ -83,7 +83,8 @@ namespace senf { ...@@ -83,7 +83,8 @@ namespace senf {
public IPv4Protocol, public IPv4Protocol,
public UDPProtocol, public UDPProtocol,
public BSDSocketProtocol, public BSDSocketProtocol,
public AddressableBSDSocketProtocol public AddressableBSDSocketProtocol,
public senf::pool_alloc_mixin<UDPv4SocketProtocol>
{ {
public: public:
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
...@@ -147,7 +148,8 @@ namespace senf { ...@@ -147,7 +148,8 @@ namespace senf {
public IPv6Protocol, public IPv6Protocol,
public UDPProtocol, public UDPProtocol,
public BSDSocketProtocol, public BSDSocketProtocol,
public AddressableBSDSocketProtocol public AddressableBSDSocketProtocol,
public senf::pool_alloc_mixin<UDPv6SocketProtocol>
{ {
public: public:
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
......
...@@ -34,7 +34,7 @@ prefix_ void * senf::pool_alloc_mixin<Self>::operator new(size_t size) ...@@ -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 // When deriving from Self you may not change the class's size without
// inheriting from pool_alloc_mixin again. See pool_alloc_mixin documentation. // inheriting from pool_alloc_mixin again. See pool_alloc_mixin documentation.
BOOST_ASSERT( size == sizeof(Self) ); BOOST_ASSERT( size <= sizeof(Self) );
#ifndef NDEBUG #ifndef NDEBUG
allocCounter(1); allocCounter(1);
#endif #endif
......
accessor accessor
addtogroup addtogroup
aListCollection aListCollection
alloc
aVectorCollection aVectorCollection
BaseParser BaseParser
berlios berlios
...@@ -22,6 +23,7 @@ dil ...@@ -22,6 +23,7 @@ dil
dontinclude dontinclude
ElementParser ElementParser
endcode endcode
eof
eth eth
ethernet ethernet
EthernetPacket EthernetPacket
...@@ -32,6 +34,9 @@ EthVLan ...@@ -32,6 +34,9 @@ EthVLan
ExampleListPolicy ExampleListPolicy
ExampleVectorPolicy ExampleVectorPolicy
ExtendedParser ExtendedParser
FileBody
filebody
FileHandle
findNext findNext
findPrev findPrev
fokus fokus
...@@ -145,6 +150,7 @@ stefan ...@@ -145,6 +150,7 @@ stefan
STL STL
struct struct
structors structors
SystemException
templated templated
todo todo
TruncatedPacketException TruncatedPacketException
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment