4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.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.
24 \brief BSDAddressingPolicyMixin public header
27 /** \defgroup addr_group Addressing classes
30 #ifndef HH_SENF_Socket_Protocols_BSDAddressingPolicy_
31 #define HH_SENF_Socket_Protocols_BSDAddressingPolicy_ 1
34 #include <senf/Socket/SocketHandle.hh>
35 #include <senf/Socket/FileHandle.hh>
36 #include <senf/Socket/SocketPolicy.hh>
37 #include <senf/Socket/CommunicationPolicy.hh>
38 #include "BSDSocketAddress.hh"
40 //#include "BSDAddressingPolicy.mpp"
41 ///////////////////////////////hh.p////////////////////////////////////////
45 /// \addtogroup policy_impl_group
48 /** \brief Non-template implementation class of BSDAddressingPolicyMixin template
52 struct BSDAddressingPolicyMixinBase
54 static void do_local(FileHandle handle, struct sockaddr * addr, socklen_t * len);
55 static void do_peer(FileHandle handle, struct sockaddr * addr, socklen_t * len);
56 static void do_bind(FileHandle handle, struct sockaddr const * addr, socklen_t len);
57 static void do_connect(FileHandle handle, struct sockaddr const * addr, socklen_t len);
60 /** \brief Template for generic AddressingPolicy implementation based on the BSD socket API
62 This template provides an implementation template to implement generic addressing policy
63 classes which rely on the standard BSD socket API for their implementation
64 (connect/bind/getsockname/getpeername).
66 The \a Address template parameter specifies the address type of the addressing policy. This
67 type must have two members: \c sockaddr_p() and \c socklen(). The first must return a
68 <tt>struct sockaddr *</tt> to the address, the second must return the size of the address in
69 bytes. The pointer returned by \c sockaddr_p() must be non-const if called on a non-const
70 address. <em>The underlying socket address stored at that pointer might be
73 This template class is inherited into addressing policy classes via private
74 inheritance. Then the members supported by the respective addressing policy are made
75 available via \c using declarations (See INet4AddressingPolicy for an Example).
77 \idea We could explicitly provide open_sockaddr_p() and close_sockaddr_p()
78 members. sockaddr_p could always return a const * whereas open_sockaddr_p should return a
79 non-const pointer. The close operation would then explicitly signal, that the new value
80 should be incorporated into the class. With our current implementation, the close member
81 would be a no-op, however this should free us from using the sockaddr values as a direct
82 storage representation of the address.
84 template <class Address>
85 struct BSDAddressingPolicyMixin
86 : private BSDAddressingPolicyMixinBase
89 template <class SPolicy>
90 static void peer(SocketHandle<SPolicy> handle, Address & addr,
91 typename IfCommunicationPolicyIs<SPolicy,ConnectedCommunicationPolicy>::type * = 0);
93 template <class SPolicy>
94 static void peer(SocketHandle<SPolicy> handle, Address & addr);
95 ///< Return address of remote peer on connected sockets
96 /**< This member is only available if the socket handles
97 communication policy is ConnectedCommunicationPolicy.
99 \param[in] handle socket handle to get peer address of
100 \param[out] addr address of remote peer */
102 static void local(FileHandle handle, Address & addr);
103 ///< Return local of socket
104 /**< \param[in] handle socket handle to check
105 \param[out] addr local socket address */
108 template <class SPolicy>
109 static void connect(SocketHandle<SPolicy> handle, Address const & addr,
110 typename IfCommunicationPolicyIs<SPolicy,ConnectedCommunicationPolicy>::type * = 0);
112 template <class SPolicy>
113 static void connect(SocketHandle<SPolicy> handle, Address const & addr);
114 ///< Connect to remote host
115 /**< This member is only available if the socket handles
116 communication policy is ConnectedCommunicationPolicy.
118 \param[in] handle socket handle
119 \param[in] addr address of remote peer to connect
122 static void bind(FileHandle handle, Address const & addr);
123 ///< Set local socket address
124 /**< \param[in] handle socket handle
125 \param[in] addr local socket address */
130 struct BSDAddressingPolicy
131 : public AddressingPolicyBase,
132 private BSDAddressingPolicyMixin<GenericBSDSocketAddress>
134 typedef GenericBSDSocketAddress Address;
136 using BSDAddressingPolicyMixin<GenericBSDSocketAddress>::peer;
137 using BSDAddressingPolicyMixin<GenericBSDSocketAddress>::local;
138 using BSDAddressingPolicyMixin<GenericBSDSocketAddress>::connect;
139 using BSDAddressingPolicyMixin<GenericBSDSocketAddress>::bind;
144 ///////////////////////////////hh.e////////////////////////////////////////
145 //#include "BSDAddressingPolicy.cci"
146 //#include "BSDAddressingPolicy.ct"
147 #include "BSDAddressingPolicy.cti"
148 //#include "BSDAddressingPolicy.mpp"
155 // c-file-style: "senf"
156 // indent-tabs-mode: nil
157 // ispell-local-dictionary: "american"
158 // compile-command: "scons -u ../test"
159 // comment-column: 40