switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Socket / Protocols / INet / TCPSocketHandle.hh
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
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
10 //
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.
14 //
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.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
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.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief TCPv4SocketHandle and TCPv6SocketHandle public header
30
31     \todo Implement possibly non-blocking connect and SO_ERROR in the
32     protocol interface
33  */
34
35 #ifndef HH_SENF_Socket_Protocols_INet_TCPSocketHandle_
36 #define HH_SENF_Socket_Protocols_INet_TCPSocketHandle_ 1
37
38 // Custom includes
39 #include "INetSocketProtocol.hh"
40 #include "TCPSocketProtocol.hh"
41 #include "INetAddressing.hh"
42 #include <senf/Socket/Protocols/BSDSocketProtocol.hh>
43 #include <senf/Socket/FramingPolicy.hh>
44 #include <senf/Socket/CommunicationPolicy.hh>
45 #include <senf/Socket/ReadWritePolicy.hh>
46 #include <senf/Socket/ProtocolClientSocketHandle.hh>
47 #include <senf/Socket/ProtocolServerSocketHandle.hh>
48
49 //#include "TCPSocketHandle.mpp"
50 //-/////////////////////////////////////////////////////////////////////////////////////////////////
51
52 namespace senf {
53
54     /// \addtogroup concrete_protocol_group
55     //\{
56
57     typedef MakeSocketPolicy<
58         INet4AddressingPolicy,
59         StreamFramingPolicy,
60         ConnectedCommunicationPolicy,
61         ReadablePolicy,
62         WriteablePolicy
63         >::policy TCPv4Socket_Policy;   ///< Socket Policy of the TCPv4 Protocol
64
65     /** \brief IPv4 TCP Socket Protocol
66
67         \par Socket Handle typedefs:
68             \ref TCPv4ClientSocketHandle (ProtocolClientSocketHandle), \ref TCPv4ServerSocketHandle
69             (ProtocolServerSocketHandle)
70
71         \par Policy Interface:
72             ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(),
73             ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer()
74
75         \par Address Type:
76             INet4SocketAddress
77
78         TCPv4SocketProtocol provides an internet protocol stream socket based on the TCP protocol
79         and IPv4 addressing.
80
81         This class is utilized as the protocol class of the ProtocolClientSocketHandle and
82         ProtocolServerSocketHandle via the Socket Handle typedefs above.
83
84         \see TCPv6SocketProtocol
85      */
86     class TCPv4SocketProtocol
87         : public ConcreteSocketProtocol<TCPv4Socket_Policy,TCPv4SocketProtocol>,
88           public TCPSocketProtocol,
89           public BSDSocketProtocol,
90           public AddressableBSDSocketProtocol
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 connect
105                                         /**< Creates a new client socket and connects to the given
106                                              address.
107
108                                              \param[in] address remote address to connect to */
109                                         /**< \note This member is implicitly called from the
110                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
111                                              constructor */
112         void init_server() const;       ///< Create server socket
113                                         /**< \note This member is implicitly called from the
114                                              ProtocolServerSocketHandle::ProtocolServerSocketHandle()
115                                              constructor */
116         void init_server(INet4SocketAddress const & address, unsigned backlog=1) const;
117                                         ///< Create server socket and listen
118                                         /**< Creates a new server socket, binds to \a address end
119                                              starts listening for new connections with a backlog of
120                                              \a backlog connections. It also enables reuseaddr().
121
122                                              \param[in] address address to listen on
123                                              \param[in] backlog size of the listen backlog */
124                                         /**< \note This member is implicitly called from the
125                                              ProtocolServerSocketHandle::ProtocolServerSocketHandle()
126                                              constructor */
127
128         //\}
129     };
130
131     typedef ProtocolClientSocketHandle<TCPv4SocketProtocol> TCPv4ClientSocketHandle;
132     typedef ProtocolServerSocketHandle<TCPv4SocketProtocol> TCPv4ServerSocketHandle;
133
134     typedef MakeSocketPolicy<
135         TCPv4Socket_Policy,
136         INet6AddressingPolicy
137         >::policy TCPv6Socket_Policy;
138
139     /** \brief IPv6 TCP Socket Protocol
140
141         \par Socket Handle typedefs:
142         \ref TCPv6ClientSocketHandle (ProtocolClientSocketHandle), \ref TCPv6ServerSocketHandle
143         (ProtocolServerSocketHandle)
144
145         \par Policy Interface:
146         ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(),
147         ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer()
148
149         \par Address Type:
150             INet6Address
151
152         TCPv6SocketProtocol provides an internet protocol stream socket based on the TCP protocol
153         and IPv6 addressing.
154
155         This class is utilized as the protocol class of the ProtocolClientSocketHandle and
156         ProtocolServerSocketHandle via the Socket Handle typedefs above.
157
158         \see TCPv4SocketProtocol
159      */
160     class TCPv6SocketProtocol
161         : public ConcreteSocketProtocol<TCPv6Socket_Policy,TCPv6SocketProtocol>,
162           public TCPSocketProtocol,
163           public BSDSocketProtocol,
164           public AddressableBSDSocketProtocol
165     {
166     public:
167         //-////////////////////////////////////////////////////////////////////////
168         // internal interface
169
170         ///\name Constructors
171         //\{
172
173         void init_client() const;       ///< Create unconnected client socket
174                                         /**< \note This member is implicitly called from the
175                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
176                                              constructor */
177         void init_client(INet6SocketAddress const & address) const;
178                                         ///< Create client socket and connect
179                                         /**< Creates a new client socket and connects to the given
180                                              address.
181
182                                              \param[in] address remote address to connect to */
183                                         /**< \note This member is implicitly called from the
184                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
185                                              constructor */
186         void init_server() const;       ///< Create server socket
187                                         /**< \note This member is implicitly called from the
188                                              ProtocolServerSocketHandle::ProtocolServerSocketHandle()
189                                              constructor */
190         void init_server(INet6SocketAddress const & address, unsigned backlog=1) const;
191                                         ///< Create server socket and listen
192                                         /**< Creates a new server socket, binds to \a address end
193                                              starts listening for new connections with a backlog of
194                                              \a backlog connections. It also enables reuseaddr().
195
196                                              \param[in] address address to listen on
197                                              \param[in] backlog size of the listen backlog */
198                                         /**< \note This member is implicitly called from the
199                                              ProtocolServerSocketHandle::ProtocolServerSocketHandle()
200                                              constructor */
201
202         //\}
203     };
204
205     typedef ProtocolClientSocketHandle<TCPv6SocketProtocol> TCPv6ClientSocketHandle;
206     typedef ProtocolServerSocketHandle<TCPv6SocketProtocol> TCPv6ServerSocketHandle;
207
208     //\}
209
210 }
211
212 //-/////////////////////////////////////////////////////////////////////////////////////////////////
213 //#include "TCPSocketHandle.cci"
214 //#include "TCPSocketHandle.ct"
215 //#include "TCPSocketHandle.cti"
216 #endif
217
218 \f
219 // Local Variables:
220 // mode: c++
221 // fill-column: 100
222 // c-file-style: "senf"
223 // indent-tabs-mode: nil
224 // ispell-local-dictionary: "american"
225 // compile-command: "scons -u test"
226 // comment-column: 40
227 // End: