// $Id:SocketPolicy.hh 218 2007-03-20 14:39:32Z tho $
//
// Copyright (C) 2006
-// Fraunhofer Institute for Open Communication Systems (FOKUS)
-// Competence Center NETwork research (NET), St. Augustin, GERMANY
+// 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
/** \file
\brief Policy Framework public header
- \todo We should probably remove BufferingPolicy from the interface, it does not make much sense
- (how did I come to include it ??)
-
- \todo Do we want to support separate read and write policies. This allows to treat pipes within
- this framework however, is this worth the effort?
-
- \idea Creating a new Socket will create 4 (!) new instances (The handle, the body, the policy
- and the protocol) of which 3 (argh) (body, policy and protocol) live on the heap. This is
- expensive. We should convert all the policy classes to singletons and assign the same
- instance to all socket bodies with the same policy. This would reduce the number of heap
- allocations per socket handle to two.
+ \idea Creating a new Socket will create 3 new instances (The handle, the body, the policy) of
+ which 2 (argh) (body, policy) live on the heap. This is expensive. We should convert all the
+ policy classes to singletons and assign the same instance to all socket bodies with the same
+ policy. This would reduce the number of heap allocations per socket handle to one (which is
+ already optimized using the pool_alloc_mixin)
*/
/** \defgroup policy_group The Policy Framework
- \htmlonly
- <map name="socketPolicy">
- <area shape="rect" alt="SocketPolicy" href="structsenf_1_1SocketPolicy.html" title="SocketPolicy" coords="276,90,558,213" />
- <area shape="rect" alt="BufferingPolicyBase" href="structsenf_1_1BufferingPolicyBase.html" title="BufferingPolicyBase" coords="25,282,190,306" />
- <area shape="rect" alt="WritePolicyBase" href="structsenf_1_1WritePolicyBase.html" title="WritePolicyBase" coords="39,243,174,268" />
- <area shape="rect" alt="ReadPolicyBase" href="structsenf_1_1ReadPolicyBase.html" title="ReadPolicyBase" coords="42,204,174,231" />
- <area shape="rect" alt="CommunicationPolicyBase" href="structsenf_1_1CommunicationPolicyBase.html" title="CommunicationPolicyBase" coords="0,166,215,193" />
- <area shape="rect" alt="FramingPolicyBase" href="structsenf_1_1FramingPolicyBase.html" title="FramingPolicyBase" coords="30,129,185,155" />
- <area shape="rect" alt="AddressingPolicyBase" href="structsenf_1_1AddressingPolicyBase.html" title="AddressingPolicyBase" coords="17,90,200,116" />
- </map>
- <img src="SocketPolicy.png" border="0" alt="Socket Policy" usemap="#socketPolicy">
- \endhtmlonly
-
+ <div class="diamap" name="SocketPolicy">
+ <span coords="39,229,182,257">\ref WritePolicyBase</span>
+ <span coords="17,76,210,105">\ref AddressingPolicyBase</span>
+ <span coords="29,114,194,143">\ref FramingPolicyBase</span>
+ <span coords="368,0,463,28">\ref PolicyBase</span>
+ <span coords="275,2,691,185">\ref SocketPolicy</span>
+ <span coords="0,152,227,181">\ref CommunicationPolicyBase</span>
+ <span coords="41,191,180,219">\ref ReadPolicyBase</span>
+ </div>
+ \htmlonly <img src="SocketPolicy.png" border="0" alt="SocketPolicy" usemap="#SocketPolicy"> \endhtmlonly
+
\section policy_group_introduction Introduction to the Policy Framework
The policy framework conceptually implements a list of parallel inheritance hierarchies each
<dt><em>readPolicy</em></dt><dd>configures the readability of the socket</dd>
- <dt><em>writePolicy</em></dt><dd>configures the writability of the socket</dd>
-
- <dt><em>bufferingPolicy</em></dt><dd>configures, if and how buffering is configured for a
- socket</dd> </dl>
+ <dt><em>writePolicy</em></dt><dd>configures the writability of the socket</dd></dl>
The template senf::SocketPolicy combines these policy axis to form a concrete socket policy. In
a concrete policy, each of these policy axis is assigned a value, the policy value. This value
from the axis base class <tt>FramingPolicyBase</tt>. This base class also doubles as
<tt>UnspecifiedFramingPolicy</tt> (which is just a typedef alias). If a policy axis is assigned
this Unspecified type, the axis is left unspecified, the concrete policy will be incomplete.
-
+
The senf::SocketPolicy template defines the behavior of a socket handle. The socket handle
instances do not implement any socket functionality themselves instead deferring the
implementation to the policy classes. The SocketHandle interface is therefore \e not implemented
separately but at the same time for each policy axis:
\code
- // This defines an incomplete policy where addressingPolicy, writePolicy and bufferingPolicy
+ // This defines an incomplete policy where addressingPolicy and writePolicy
// are unspecified
typedef senf::MakeSocketPolicy<
senf::StreamFramingPolicy,
// StreamFramingPolicy,
// ConnectedCommunicationPolicy,
// ReadablePolicy,
- // WritablePolicy,
- // SocketBufferingPolicy>::policy
+ // WritablePolicy>::policy
senf::TCPv4ClientSocketHandle tcpHandle (...);
MyReadableHandle myHandle (tcpHandle); // Conversion to more basic socket handle
meta-programming are needed. However, this information is only needed if you want to write new
policy classes or want to use the policy framework explicitly for your own involved
optimizations ... or if you are just plain curious :-)
-
+
In the following discussion we will use the following conventions:
\li \e Axis is one or \c AddressingPolicy, \c FramingPolicy, \c CommunicationPolicy, \c
- ReadPolicy, \c WritePolicy or \c BufferingPolicy
+ ReadPolicy or \c WritePolicy
\li \e socketPolicy is any socket policy (that is, an instantiation of the SocketPolicy
template)
\li \e trait is an any policy class (that is, any class derived from one of the axis base
derives from SocketPolicyBase. This is simpler than checking the template directly).</dd>
<dt>\c template \c SocketPolicy < \e addressingPolicy, \e framingPolicy, \e communicationPolicy,
- \e readPolicy, \e writePolicy, \e bufferingPolicy ></dt> <dd>This is the central SocketPolicy
+ \e readPolicy, \e writePolicy ></dt> <dd>This is the central SocketPolicy
template. It combines a complete set of policy classes, one for each axis.</dd>
<dt>\c template \c MakeSocketPolicy < \e args ></dt> <dd>\c MakeSocketPolicy is a template
\section policy_implement Implementing Policy Classes
- To define a new policy class, derive from the corresponding base class for your policy
- axes. The only policy axis which might possibly need to be extended are the addressing policy
- (AddressingPolicyBase) and the buffering policy (BufferingPolicyBase). See the Documentation of
- these classes for more information on which members can be implemented.
+ To define a new policy class, derive from the corresponding base class for your policy axes. The
+ only policy axis which might possibly need to be extended is the addressing policy
+ (AddressingPolicyBase). See the Documentation of these classes for more information on which
+ members can be implemented.
All members you define must be static. For any of the policy classes, you must only define those
members which are supported by your implementation. If you leave out a member you automatically
\code
struct ExampleAddressingPolicy
{
- template <class Policy>
- void connect(senf::SocketHandle<Policy> handle, Address & addr,
+ template <class SPolicy>
+ void connect(senf::SocketHandle<SPolicy> handle, Address & addr,
typename senf::IfCommmunicationPolicyIs<
- Policy, senf::ConnectedCommunicationPolicy>::type * = 0);
+ SPolicy, senf::ConnectedCommunicationPolicy>::type * = 0);
};
\endcode
as base classes to build other policy classes.
*/
-#ifndef HH_SocketPolicy_
-#define HH_SocketPolicy_ 1
+#ifndef HH_SENF_Socket_SocketPolicy_
+#define HH_SENF_Socket_SocketPolicy_ 1
// Custom includes
(FramingPolicy) \
(CommunicationPolicy) \
(ReadPolicy) \
- (WritePolicy) \
- (BufferingPolicy)
+ (WritePolicy)
// Wer define these classes explicitly (and not with some macro
// magic) because
*/
struct AddressingPolicyBase
{
- virtual ~AddressingPolicyBase() {}
+ virtual ~AddressingPolicyBase();
class Address { Address(); };
};
*/
struct FramingPolicyBase
{
- virtual ~FramingPolicyBase() {}
+ virtual ~FramingPolicyBase();
};
/** \brief Policy defining, how peers are selected
The \c listen member is straight forward. The \c accept() member must return a new file
descriptor (which will be used to create a new SocketHandle of the correct
- type).
+ type).
\note This Policy only has two meaningful states: ConnectedCommunicationPolicy and
UnconnectedCommunicationPolicy. It is probably not sensible to define a new
*/
struct CommunicationPolicyBase
{
- virtual ~CommunicationPolicyBase() {}
+ virtual ~CommunicationPolicyBase();
};
/** \brief Policy defining the readability
*/
struct ReadPolicyBase
{
- virtual ~ReadPolicyBase() {}
+ virtual ~ReadPolicyBase();
};
/** \brief Policy defining the writability
*/
struct WritePolicyBase
{
- virtual ~WritePolicyBase() {}
- };
-
- /** \brief Policy defining the buffering interface
-
- The BufferingPolicy defines the buffer handling of the socket. It may provide the following
- members:
-
- \see policy_group
- */
- struct BufferingPolicyBase
- {
- virtual ~BufferingPolicyBase() {}
+ virtual ~WritePolicyBase();
};
// The implementation file will for each Policy declared above
information.
*/
AddressingPolicyBase const & theAddressingPolicy() const = 0;
+
+ virtual ~SocketPolicyBase();
};
/** \brief Collection of policy classes