72a4f554302eef9ba88770a41127bfc657ab33d4
[senf.git] / Socket / UDPSocketHandle.hh
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.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 "BSDSocketProtocol.hh"
37 #include "FramingPolicy.hh"
38 #include "CommunicationPolicy.hh"
39 #include "ReadWritePolicy.hh"
40 #include "BufferingPolicy.hh"
41 #include "ProtocolClientSocketHandle.hh"
42
43 //#include "UDPSocketHandle.mpp"
44 ///////////////////////////////hh.p////////////////////////////////////////
45
46 namespace senf {
47
48     /// \addtogroup concrete_protocol_group
49     /// @{
50
51     typedef MakeSocketPolicy<
52         INet4AddressingPolicy,
53         DatagramFramingPolicy,
54         UnconnectedCommunicationPolicy,
55         ReadablePolicy,
56         WriteablePolicy,
57         SocketBufferingPolicy
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::write(), ClientSocketHandle::bind(),
67         ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer(),
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 BSDSocketProtocol,
86           public AddressableBSDSocketProtocol
87     {
88     public:
89         ///////////////////////////////////////////////////////////////////////////
90         // internal interface
91
92         ///\name Constructors
93         ///@{
94
95         void init_client() const;       ///< Create unconnected client socket
96                                         /**< \note This member is implicitly called from the
97                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
98                                              constructor */
99         void init_client(INet4Address const & address) const;
100                                         ///< Create client socket and connect
101                                         /**< Creates a new client socket and connects to the given
102                                              address.
103
104                                              \param[in] address remote address to connect to */
105                                         /**< \note This member is implicitly called from the
106                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
107                                              constructor */
108
109         ///@}
110         ///\name Abstract Interface Implementation
111
112         std::auto_ptr<SocketProtocol> clone() const;
113
114         ///@}
115     };
116
117     typedef ProtocolClientSocketHandle<UDPv4SocketProtocol> UDPv4ClientSocketHandle;
118
119     typedef MakeSocketPolicy<
120         UDPv4Socket_Policy,
121         INet6AddressingPolicy
122         >::policy UDPv6Socket_Policy;
123
124     /** \brief IPv6 UDP Socket Protocol
125
126         \par Socket Handle typedefs:
127         \ref UDPv6ClientSocketHandle (ProtocolClientSocketHandle)
128
129         \par Policy Interface:
130         ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(),
131         ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer(),
132         ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf()
133
134         \par Address Type:
135         INet6Address
136
137         UDPv6SocketProtocol provides an internet protocol stream socket based on the UDP protocol
138         and IPv6 addressing.
139
140         This class is utilized as the protocol class of the ProtocolClientSocketHandle
141         via the Socket Handle typedefs above.
142
143         \see UDPv4SocketProtocol
144      */
145     class UDPv6SocketProtocol
146         : public ConcreteSocketProtocol<UDPv6Socket_Policy>,
147           public IPv6Protocol,
148           public UDPProtocol,
149           public BSDSocketProtocol,
150           public AddressableBSDSocketProtocol
151     {
152     public:
153         ///////////////////////////////////////////////////////////////////////////
154         // internal interface
155
156         ///\name Constructors
157         ///@{
158
159         void init_client() const;       ///< Create unconnected client socket
160                                         /**< \note This member is implicitly called from the
161                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
162                                              constructor */
163         void init_client(INet6SocketAddress const & address) const;
164                                         ///< Create client socket and connect
165                                         /**< Creates a new client socket and connects to the given
166                                              address.
167
168                                              \param[in] address remote address to connect to */
169                                         /**< \note This member is implicitly called from the
170                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
171                                              constructor */
172
173         ///@}
174         ///\name Abstract Interface Implementation
175
176         std::auto_ptr<SocketProtocol> clone() const;
177
178         ///@}
179     };
180
181     typedef ProtocolClientSocketHandle<UDPv6SocketProtocol> UDPv6ClientSocketHandle;
182
183     /// @}
184
185 }
186
187 ///////////////////////////////hh.e////////////////////////////////////////
188 //#include "UDPSocketHandle.cci"
189 //#include "UDPSocketHandle.ct"
190 //#include "UDPSocketHandle.cti"
191 #endif
192
193 \f
194 // Local Variables:
195 // mode: c++
196 // fill-column: 100
197 // c-file-style: "senf"
198 // indent-tabs-mode: nil
199 // ispell-local-dictionary: "american"
200 // compile-command: "scons -u test"
201 // End: