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/CommunicationPolicy.hh>
37 #include "BSDSocketAddress.hh"
39 //#include "BSDAddressingPolicy.mpp"
40 ///////////////////////////////hh.p////////////////////////////////////////
44 /// \addtogroup policy_impl_group
47 /** \brief Non-template implementation class of BSDAddressingPolicyMixin template
51 struct BSDAddressingPolicyMixinBase
53 static void do_local(FileHandle const & handle, struct sockaddr * addr, socklen_t * len);
54 static void do_peer(FileHandle const & handle, struct sockaddr * addr, socklen_t * len);
55 static void do_bind(FileHandle const & handle, struct sockaddr const * addr, socklen_t len);
56 static void do_connect(FileHandle const & handle, struct sockaddr const * addr, socklen_t len);
59 /** \brief Template for generic AddressingPolicy implementation based on the BSD socket API
61 This template provides an implementation template to implement generic addressing policy
62 classes which rely on the standard BSD socket API for their implementation
63 (connect/bind/getsockname/getpeername).
65 The \a Address template parameter specifies the address type of the addressing policy. This
66 type must have two members: \c sockaddr_p() and \c socklen(). The first must return a
67 <tt>struct sockaddr *</tt> to the address, the second must return the size of the address in
68 bytes. The pointer returned by \c sockaddr_p() must be non-const if called on a non-const
69 address. <em>The underlying socket address stored at that pointer might be
72 This template class is inherited into addressing policy classes via private
73 inheritance. Then the members supported by the respective addressing policy are made
74 available via \c using declarations (See INet4AddressingPolicy for an Example).
76 \idea We could explicitly provide open_sockaddr_p() and close_sockaddr_p()
77 members. sockaddr_p could always return a const * whereas open_sockaddr_p should return a
78 non-const pointer. The close operation would then explicitly signal, that the new value
79 should be incorporated into the class. With our current implementation, the close member
80 would be a no-op, however this should free us from using the sockaddr values as a direct
81 storage representation of the address.
83 template <class Address>
84 struct BSDAddressingPolicyMixin
85 : private BSDAddressingPolicyMixinBase
88 template <class SPolicy>
89 static void peer(SocketHandle<SPolicy> const & handle, Address & addr,
90 typename IfCommunicationPolicyIs<SPolicy,ConnectedCommunicationPolicy>::type * = 0);
92 template <class SPolicy>
93 static void peer(SocketHandle<SPolicy> const & handle, Address & addr);
94 ///< Return address of remote peer on connected sockets
95 /**< This member is only available if the socket handles
96 communication policy is ConnectedCommunicationPolicy.
98 \param[in] handle socket handle to get peer address of
99 \param[out] addr address of remote peer */
101 static void local(FileHandle const & handle, Address & addr);
102 ///< Return local of socket
103 /**< \param[in] handle socket handle to check
104 \param[out] addr local socket address */
107 template <class SPolicy>
108 static void connect(SocketHandle<SPolicy> const & handle, Address const & addr,
109 typename IfCommunicationPolicyIs<SPolicy,ConnectedCommunicationPolicy>::type * = 0);
111 template <class SPolicy>
112 static void connect(SocketHandle<SPolicy> const & handle, Address const & addr);
113 ///< Connect to remote host
114 /**< This member is only available if the socket handles
115 communication policy is ConnectedCommunicationPolicy.
117 \param[in] handle socket handle
118 \param[in] addr address of remote peer to connect
121 static void bind(FileHandle const & handle, Address const & addr);
122 ///< Set local socket address
123 /**< \param[in] handle socket handle
124 \param[in] addr local socket address */
129 struct BSDAddressingPolicy
130 : public AddressingPolicyBase,
131 private BSDAddressingPolicyMixin<GenericBSDSocketAddress>
133 typedef GenericBSDSocketAddress Address;
135 using BSDAddressingPolicyMixin<GenericBSDSocketAddress>::peer;
136 using BSDAddressingPolicyMixin<GenericBSDSocketAddress>::local;
137 using BSDAddressingPolicyMixin<GenericBSDSocketAddress>::connect;
138 using BSDAddressingPolicyMixin<GenericBSDSocketAddress>::bind;
143 ///////////////////////////////hh.e////////////////////////////////////////
144 //#include "BSDAddressingPolicy.cci"
145 //#include "BSDAddressingPolicy.ct"
146 #include "BSDAddressingPolicy.cti"
147 //#include "BSDAddressingPolicy.mpp"
154 // c-file-style: "senf"
155 // indent-tabs-mode: nil
156 // ispell-local-dictionary: "american"
157 // compile-command: "scons -u ../test"
158 // comment-column: 40