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