4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <stefan.bund@fokus.fraunhofer.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 \idea We should optimize the protocol handling. Allocating a
26 protocol instance for every socket body seems quite
27 wasteful. However I have no idea, how to access the socket
28 handle from within the protocol interface if the protocol
29 class is a singleton. Maybe, we'll have some other idea to
30 reduce the number of heap allocations (like deriving the
31 SocketProtocol class (private? protected?) from the
32 SocketBody. (private inheritance is a form of 'has-a' instead
33 of 'is-a' which would fit very well here). This would allow to
34 reduce the number of heap-allocations per socket to one which
38 /** \defgroup protocol_group The Protocol Classes
40 \image html Protocols.png
42 The socket handle classes and templates only implement the most
43 important socket API methods using the policy framework. To access
44 the complete API, the protocol interface is provided. Access to
45 the protocol interface is only possible via
46 senf::ProtocolClientSocketHandle and
47 senf::ProtocolServerSocketHandle which have the necessary \c
48 protocol() member. This member returns a reference to the protocol
49 class instance which contains members covering all the API
50 functions (mostly setsockopt/getsockopt related calls but there
51 may be more, this is completely up to the implementor of the
52 protocol class) not found in the SocketHandle interface. The
53 protocol interface is specific to the protocol. It's
54 implementation is quite free. The standard protocols are
55 implemented using a simple multiple-inheritance hierarchy as shown
58 Since the protocol class is protocol specific (how intelligent
59 ...), the protocol class also defines the complete socket policy
60 to be used with it's protocol. Complete meaning, that every policy
61 axis must be assigned it's the most specific (that is derived)
62 policy class to be used with the protocol.
65 #ifndef HH_SocketProtocol_
66 #define HH_SocketProtocol_ 1
69 #include <boost/utility.hpp>
70 /** \fixme this is not nice. The includes and predefs should be restructured */
71 #include "SocketHandle.ih"
73 //#include "SocketProtocol.mpp"
74 ///////////////////////////////hh.p////////////////////////////////////////
78 /// \addtogroup protocol_group
81 class SocketPolicyBase;
83 class SocketProtocol : boost::noncopyable
86 ///////////////////////////////////////////////////////////////////////////
89 ///////////////////////////////////////////////////////////////////////////
90 ///\name Structors and default members
94 virtual ~SocketProtocol() = 0;
96 // default default constructor
98 // no conversion constructors
101 ///////////////////////////////////////////////////////////////////////////
103 SocketBody & body() const;
104 virtual SocketPolicyBase const & policy() const = 0;
106 ///////////////////////////////////////////////////////////////////////////
109 virtual std::auto_ptr<SocketProtocol> clone() const = 0;
110 virtual unsigned available() const = 0;
111 virtual bool eof() const = 0;
112 virtual void state(SocketStateMap & map, unsigned lod) const;
117 // backpointer to owning SocketBody instance
119 friend class SocketBody;
122 template <class SocketPolicy>
123 class ConcreteSocketProtocol
124 : public virtual SocketProtocol
127 ///////////////////////////////////////////////////////////////////////////
130 typedef SocketPolicy Policy;
132 ///////////////////////////////////////////////////////////////////////////
133 ///\name Structors and default members
136 ~ConcreteSocketProtocol() = 0;
138 // no default constructor
140 // no conversion constructors
143 ///////////////////////////////////////////////////////////////////////////
145 Policy const & policy() const;
157 ///////////////////////////////hh.e////////////////////////////////////////
158 #include "SocketProtocol.cci"
159 //#include "SocketProtocol.ct"
160 #include "SocketProtocol.cti"
166 // c-file-style: "senf"