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