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