f55f55dc6c30e917b627aa75d52c4736a19360c2
[senf.git] / Socket / Protocols / INet / TCPSocketHandle.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 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 "Utils/pool_alloc_mixin.hh"
35 #include "INetProtocol.hh"
36 #include "TCPProtocol.hh"
37 #include "Socket/Protocols/BSDSocketProtocol.hh"
38 #include "Socket/FramingPolicy.hh"
39 #include "Socket/CommunicationPolicy.hh"
40 #include "Socket/ReadWritePolicy.hh"
41 #include "Socket/BufferingPolicy.hh"
42 #include "Socket/ProtocolClientSocketHandle.hh"
43 #include "Socket/ProtocolServerSocketHandle.hh"
44
45 //#include "TCPSocketHandle.mpp"
46 ///////////////////////////////hh.p////////////////////////////////////////
47
48 namespace senf {
49
50     /// \addtogroup concrete_protocol_group
51     /// @{
52
53     typedef MakeSocketPolicy<
54         INet4AddressingPolicy,
55         StreamFramingPolicy,
56         ConnectedCommunicationPolicy,
57         ReadablePolicy,
58         WriteablePolicy,
59         SocketBufferingPolicy
60         >::policy TCPv4Socket_Policy;   ///< Socket Policy of the TCPv4 Protocol
61
62     /** \brief IPv4 TCP Socket Protocol
63
64         \par Socket Handle typedefs:
65         \ref TCPv4ClientSocketHandle (ProtocolClientSocketHandle), \ref TCPv4ServerSocketHandle
66         (ProtocolServerSocketHandle)
67
68         \par Policy Interface:
69         ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(),
70         ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer(),
71         ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf()
72
73         \par Address Type:
74         INet4Address
75
76         TCPv4SocketProtocol provides an internet protocol stream socket based on the TCP protocol
77         and IPv4 addressing.
78
79         This class is utilized as the protocol class of the ProtocolClientSocketHandle and
80         ProtocolServerSocketHandle via the Socket Handle typedefs above.
81
82         \see TCPv6SocketProtocol
83      */
84     class TCPv4SocketProtocol
85         : public ConcreteSocketProtocol<TCPv4Socket_Policy>,
86           public IPv4Protocol,
87           public TCPProtocol,
88           public BSDSocketProtocol,
89           public AddressableBSDSocketProtocol,
90           public senf::pool_alloc_mixin<TCPv4SocketProtocol>
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         ///\name Abstract Interface Implementation
130
131         std::auto_ptr<SocketProtocol> clone() const;
132
133         ///@}
134     };
135
136     typedef ProtocolClientSocketHandle<TCPv4SocketProtocol> TCPv4ClientSocketHandle;
137     typedef ProtocolServerSocketHandle<TCPv4SocketProtocol> TCPv4ServerSocketHandle;
138
139     typedef MakeSocketPolicy<
140         TCPv4Socket_Policy,
141         INet6AddressingPolicy
142         >::policy TCPv6Socket_Policy;
143
144     /** \brief IPv6 TCP Socket Protocol
145
146         \par Socket Handle typedefs:
147         \ref TCPv6ClientSocketHandle (ProtocolClientSocketHandle), \ref TCPv6ServerSocketHandle
148         (ProtocolServerSocketHandle)
149
150         \par Policy Interface:
151         ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(),
152         ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer(),
153         ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf()
154
155         \par Address Type:
156         INet6Address
157
158         TCPv6SocketProtocol provides an internet protocol stream socket based on the TCP protocol
159         and IPv6 addressing.
160
161         This class is utilized as the protocol class of the ProtocolClientSocketHandle and
162         ProtocolServerSocketHandle via the Socket Handle typedefs above.
163
164         \see TCPv4SocketProtocol
165      */
166     class TCPv6SocketProtocol
167         : public ConcreteSocketProtocol<TCPv6Socket_Policy>,
168           public IPv6Protocol,
169           public TCPProtocol,
170           public BSDSocketProtocol,
171           public AddressableBSDSocketProtocol,
172           public senf::pool_alloc_mixin<TCPv6SocketProtocol>
173     {
174     public:
175         ///////////////////////////////////////////////////////////////////////////
176         // internal interface
177
178         ///\name Constructors
179         ///@{
180
181         void init_client() const;       ///< Create unconnected client socket
182                                         /**< \note This member is implicitly called from the
183                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
184                                              constructor */
185         void init_client(INet6SocketAddress const & address) const;
186                                         ///< Create client socket and connect
187                                         /**< Creates a new client socket and connects to the given
188                                              address.
189
190                                              \param[in] address remote address to connect to */
191                                         /**< \note This member is implicitly called from the
192                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
193                                              constructor */
194         void init_server() const;       ///< Create server socket
195                                         /**< \note This member is implicitly called from the
196                                              ProtocolServerSocketHandle::ProtocolServerSocketHandle()
197                                              constructor */
198         void init_server(INet6SocketAddress const & address, unsigned backlog=1) const;
199                                         ///< Create server socket and listen
200                                         /**< Creates a new server socket, binds to \a address end
201                                              starts listening for new connections with a backlog of
202                                              \a backlog connections. It also enables reuseaddr().
203
204                                              \param[in] address address to listen on
205                                              \param[in] backlog size of the listen backlog */
206                                         /**< \note This member is implicitly called from the
207                                              ProtocolServerSocketHandle::ProtocolServerSocketHandle()
208                                              constructor */
209
210         ///@}
211         ///\name Abstract Interface Implementation
212
213         std::auto_ptr<SocketProtocol> clone() const;
214
215         ///@}
216     };
217
218     typedef ProtocolClientSocketHandle<TCPv6SocketProtocol> TCPv6ClientSocketHandle;
219     typedef ProtocolServerSocketHandle<TCPv6SocketProtocol> TCPv6ServerSocketHandle;
220
221     /// @}
222
223 }
224
225 ///////////////////////////////hh.e////////////////////////////////////////
226 //#include "TCPSocketHandle.cci"
227 //#include "TCPSocketHandle.ct"
228 //#include "TCPSocketHandle.cti"
229 #endif
230
231 \f
232 // Local Variables:
233 // mode: c++
234 // fill-column: 100
235 // c-file-style: "senf"
236 // indent-tabs-mode: nil
237 // ispell-local-dictionary: "american"
238 // compile-command: "scons -u test"
239 // comment-column: 40
240 // End: