Merged revisions 570-572,574-575,578-579,581-595,598-611 via svnmerge from
[senf.git] / Socket / Protocols / INet / UDPSocketHandle.hh
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institute for Open Communication Systems (FOKUS) 
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY 
6 //     Stefan Bund <g0dil@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief UDPv4SocketHandle and UDPv6SocketHandle public header
25
26     \todo Implement possibly non-blocking connect and SO_ERROR in the
27     protocol interface
28  */
29
30 #ifndef HH_UDPSocketHandle_
31 #define HH_UDPSocketHandle_ 1
32
33 // Custom includes
34 #include "INetProtocol.hh"
35 #include "UDPProtocol.hh"
36 #include "MulticastProtocol.hh"
37 #include "../../../Socket/Protocols/BSDSocketProtocol.hh"
38 #include "../../../Socket/Protocols/DatagramSocketProtocol.hh"
39 #include "../../../Socket/FramingPolicy.hh"
40 #include "../../../Socket/CommunicationPolicy.hh"
41 #include "../../../Socket/ReadWritePolicy.hh"
42 #include "../../../Socket/ProtocolClientSocketHandle.hh"
43
44 //#include "UDPSocketHandle.mpp"
45 ///////////////////////////////hh.p////////////////////////////////////////
46
47 namespace senf {
48
49     /// \addtogroup concrete_protocol_group
50     /// @{
51
52     typedef MakeSocketPolicy<
53         INet4AddressingPolicy,
54         DatagramFramingPolicy,
55         UnconnectedCommunicationPolicy,
56         ReadablePolicy,
57         WriteablePolicy
58         >::policy UDPv4Socket_Policy;   ///< Socket Policy of the UDPv4 Protocol
59
60     /** \brief IPv4 UDP Socket Protocol
61
62         \par Socket Handle typedefs:
63             \ref UDPv4ClientSocketHandle (ProtocolClientSocketHandle)
64
65         \par Policy Interface:
66             ClientSocketHandle::read(), ClientSocketHandle::readfrom(),
67             ClientSocketHandle::writeto(), ClientSocketHandle::bind(), ClientSocketHandle::local(),
68             ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf()
69
70         \par Address Type:
71             INet4Address
72
73         UDPv4SocketProtocol provides an internet protocol stream socket based on the UDP protocol
74         and IPv4 addressing.
75
76         This class is utilized as the protocol class of the ProtocolClientSocketHandle
77         via the Socket Handle typedefs above.
78
79         \see UDPv6SocketProtocol
80      */
81     class UDPv4SocketProtocol
82         : public ConcreteSocketProtocol<UDPv4Socket_Policy>,
83           public IPv4Protocol,
84           public UDPProtocol,
85           public MulticastProtocol,
86           public INet4MulticastProtocol,
87           public BSDSocketProtocol,
88           public DatagramSocketProtocol,
89           public AddressableBSDSocketProtocol,
90           public senf::pool_alloc_mixin<UDPv4SocketProtocol>
91     {
92     public:
93         ///////////////////////////////////////////////////////////////////////////
94         // internal interface
95
96         ///\name Constructors
97         ///@{
98
99         void init_client() const;       ///< Create unconnected client socket
100                                         /**< \note This member is implicitly called from the
101                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
102                                              constructor */
103         void init_client(INet4SocketAddress const & address) const;
104                                         ///< Create client socket and bind
105                                         /**< Creates a new client socket and bind to the given
106                                              address.
107                                              \param[in] address local address to bind to */
108                                         /**< \note This member is implicitly called from the
109                                             ProtocolClientSocketHandle::ProtocolClientSocketHandle()
110                                              constructor */
111
112         ///@}
113         ///\name Abstract Interface Implementation
114
115         std::auto_ptr<SocketProtocol> clone() const;
116
117         ///@}
118
119     };
120
121     typedef ProtocolClientSocketHandle<UDPv4SocketProtocol> UDPv4ClientSocketHandle;
122
123     typedef MakeSocketPolicy<
124         UDPv4Socket_Policy,
125         INet6AddressingPolicy
126         >::policy UDPv6Socket_Policy;
127
128     /** \brief IPv6 UDP Socket Protocol
129
130         \par Socket Handle typedefs:
131         \ref UDPv6ClientSocketHandle (ProtocolClientSocketHandle)
132
133         \par Policy Interface: 
134             ClientSocketHandle::read(), ClientSocketHandle::readfrom(),
135             ClientSocketHandle::writeto(), ClientSocketHandle::bind(), ClientSocketHandle::local(),
136             ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf()
137
138         \par Address Type:
139             INet6Address
140
141         UDPv6SocketProtocol provides an internet protocol stream socket based on the UDP protocol
142         and IPv6 addressing.
143
144         This class is utilized as the protocol class of the ProtocolClientSocketHandle
145         via the Socket Handle typedefs above.
146
147         \see UDPv4SocketProtocol
148      */
149     class UDPv6SocketProtocol
150         : public ConcreteSocketProtocol<UDPv6Socket_Policy>,
151           public IPv6Protocol,
152           public UDPProtocol,
153           public MulticastProtocol,
154           public INet6MulticastProtocol,
155           public BSDSocketProtocol,
156           public DatagramSocketProtocol,
157           public AddressableBSDSocketProtocol,
158           public senf::pool_alloc_mixin<UDPv6SocketProtocol>
159     {
160     public:
161         ///////////////////////////////////////////////////////////////////////////
162         // internal interface
163
164         ///\name Constructors
165         ///@{
166
167         void init_client() const;       ///< Create unconnected client socket
168                                         /**< \note This member is implicitly called from the
169                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
170                                              constructor */
171         void init_client(INet6SocketAddress const & address) const;
172                                         ///< Create client socket and connect
173                                         /**< Creates a new client socket and bind to the given
174                                              address.
175                                              \param[in] address local address to bind to */
176                                         /**< \note This member is implicitly called from the
177                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
178                                              constructor */
179
180         ///@}
181         ///\name Abstract Interface Implementation
182
183         std::auto_ptr<SocketProtocol> clone() const;
184
185         ///@}
186     };
187
188     typedef ProtocolClientSocketHandle<UDPv6SocketProtocol> UDPv6ClientSocketHandle;
189
190     /// @}
191
192 }
193
194 ///////////////////////////////hh.e////////////////////////////////////////
195 //#include "UDPSocketHandle.cci"
196 //#include "UDPSocketHandle.ct"
197 //#include "UDPSocketHandle.cti"
198 #endif
199
200 \f
201 // Local Variables:
202 // mode: c++
203 // fill-column: 100
204 // c-file-style: "senf"
205 // indent-tabs-mode: nil
206 // ispell-local-dictionary: "american"
207 // compile-command: "scons -u test"
208 // comment-column: 40
209 // End: