4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief BSDAddressingPolicyMixin public header
32 /** \defgroup addr_group Addressing classes
35 #ifndef HH_SENF_Socket_Protocols_BSDAddressingPolicy_
36 #define HH_SENF_Socket_Protocols_BSDAddressingPolicy_ 1
39 #include <senf/Socket/SocketHandle.hh>
40 #include <senf/Socket/FileHandle.hh>
41 #include <senf/Socket/CommunicationPolicy.hh>
42 #include "BSDSocketAddress.hh"
44 //#include "BSDAddressingPolicy.mpp"
45 //-/////////////////////////////////////////////////////////////////////////////////////////////////
49 /// \addtogroup policy_impl_group
52 /** \brief Non-template implementation class of BSDAddressingPolicyMixin template
56 struct BSDAddressingPolicyMixinBase
58 static void do_local(FileHandle const & handle, struct sockaddr * addr, socklen_t * len);
59 static void do_peer(FileHandle const & handle, struct sockaddr * addr, socklen_t * len);
60 static void do_bind(FileHandle const & handle, struct sockaddr const * addr, socklen_t len);
61 static void do_connect(FileHandle const & handle, struct sockaddr const * addr, socklen_t len);
64 /** \brief Template for generic AddressingPolicy implementation based on the BSD socket API
66 This template provides an implementation template to implement generic addressing policy
67 classes which rely on the standard BSD socket API for their implementation
68 (connect/bind/getsockname/getpeername).
70 The \a Address template parameter specifies the address type of the addressing policy. This
71 type must have two members: \c sockaddr_p() and \c socklen(). The first must return a
72 <tt>struct sockaddr *</tt> to the address, the second must return the size of the address in
73 bytes. The pointer returned by \c sockaddr_p() must be non-const if called on a non-const
74 address. <em>The underlying socket address stored at that pointer might be
77 This template class is inherited into addressing policy classes via private
78 inheritance. Then the members supported by the respective addressing policy are made
79 available via \c using declarations (See INet4AddressingPolicy for an Example).
81 \idea We could explicitly provide open_sockaddr_p() and close_sockaddr_p()
82 members. sockaddr_p could always return a const * whereas open_sockaddr_p should return a
83 non-const pointer. The close operation would then explicitly signal, that the new value
84 should be incorporated into the class. With our current implementation, the close member
85 would be a no-op, however this should free us from using the sockaddr values as a direct
86 storage representation of the address.
88 template <class Address>
89 struct BSDAddressingPolicyMixin
90 : private BSDAddressingPolicyMixinBase
93 template <class SPolicy>
94 static void peer(SocketHandle<SPolicy> const & handle, Address & addr,
95 typename IfCommunicationPolicyIs<SPolicy,ConnectedCommunicationPolicy>::type * = 0);
97 template <class SPolicy>
98 static void peer(SocketHandle<SPolicy> const & handle, Address & addr);
99 ///< Return address of remote peer on connected sockets
100 /**< This member is only available if the socket handles
101 communication policy is ConnectedCommunicationPolicy.
103 \param[in] handle socket handle to get peer address of
104 \param[out] addr address of remote peer */
106 static void local(FileHandle const & handle, Address & addr);
107 ///< Return local of socket
108 /**< \param[in] handle socket handle to check
109 \param[out] addr local socket address */
112 template <class SPolicy>
113 static void connect(SocketHandle<SPolicy> const & handle, Address const & addr,
114 typename IfCommunicationPolicyIs<SPolicy,ConnectedCommunicationPolicy>::type * = 0);
116 template <class SPolicy>
117 static void connect(SocketHandle<SPolicy> const & handle, Address const & addr);
118 ///< Connect to remote host
119 /**< This member is only available if the socket handles
120 communication policy is ConnectedCommunicationPolicy.
122 \param[in] handle socket handle
123 \param[in] addr address of remote peer to connect
126 static void bind(FileHandle const & handle, Address const & addr);
127 ///< Set local socket address
128 /**< \param[in] handle socket handle
129 \param[in] addr local socket address */
134 struct BSDAddressingPolicy
135 : public AddressingPolicyBase,
136 private BSDAddressingPolicyMixin<GenericBSDSocketAddress>
138 typedef GenericBSDSocketAddress Address;
140 using BSDAddressingPolicyMixin<GenericBSDSocketAddress>::peer;
141 using BSDAddressingPolicyMixin<GenericBSDSocketAddress>::local;
142 using BSDAddressingPolicyMixin<GenericBSDSocketAddress>::connect;
143 using BSDAddressingPolicyMixin<GenericBSDSocketAddress>::bind;
148 //-/////////////////////////////////////////////////////////////////////////////////////////////////
149 //#include "BSDAddressingPolicy.cci"
150 //#include "BSDAddressingPolicy.ct"
151 #include "BSDAddressingPolicy.cti"
152 //#include "BSDAddressingPolicy.mpp"
159 // c-file-style: "senf"
160 // indent-tabs-mode: nil
161 // ispell-local-dictionary: "american"
162 // compile-command: "scons -u ../test"
163 // comment-column: 40