4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
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.
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.
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.
24 \brief TCPv4SocketHandle and TCPv6SocketHandle public header
26 \todo Implement possibly non-blocking connect and SO_ERROR in the
30 #ifndef HH_TCPSocketHandle_
31 #define HH_TCPSocketHandle_ 1
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/ProtocolClientSocketHandle.hh"
42 #include "../../../Socket/ProtocolServerSocketHandle.hh"
44 //#include "TCPSocketHandle.mpp"
45 ///////////////////////////////hh.p////////////////////////////////////////
49 /// \addtogroup concrete_protocol_group
52 typedef MakeSocketPolicy<
53 INet4AddressingPolicy,
55 ConnectedCommunicationPolicy,
58 >::policy TCPv4Socket_Policy; ///< Socket Policy of the TCPv4 Protocol
60 /** \brief IPv4 TCP Socket Protocol
62 \par Socket Handle typedefs:
63 \ref TCPv4ClientSocketHandle (ProtocolClientSocketHandle), \ref TCPv4ServerSocketHandle
64 (ProtocolServerSocketHandle)
66 \par Policy Interface:
67 ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(),
68 ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer(),
69 ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf()
74 TCPv4SocketProtocol provides an internet protocol stream socket based on the TCP protocol
77 This class is utilized as the protocol class of the ProtocolClientSocketHandle and
78 ProtocolServerSocketHandle via the Socket Handle typedefs above.
80 \see TCPv6SocketProtocol
82 class TCPv4SocketProtocol
83 : public ConcreteSocketProtocol<TCPv4Socket_Policy>,
86 public BSDSocketProtocol,
87 public AddressableBSDSocketProtocol,
88 public senf::pool_alloc_mixin<TCPv4SocketProtocol>
91 ///////////////////////////////////////////////////////////////////////////
97 void init_client() const; ///< Create unconnected client socket
98 /**< \note This member is implicitly called from the
99 ProtocolClientSocketHandle::ProtocolClientSocketHandle()
101 void init_client(INet4SocketAddress const & address) const;
102 ///< Create client socket and connect
103 /**< Creates a new client socket and connects to the given
106 \param[in] address remote address to connect to */
107 /**< \note This member is implicitly called from the
108 ProtocolClientSocketHandle::ProtocolClientSocketHandle()
110 void init_server() const; ///< Create server socket
111 /**< \note This member is implicitly called from the
112 ProtocolServerSocketHandle::ProtocolServerSocketHandle()
114 void init_server(INet4SocketAddress const & address, unsigned backlog=1) const;
115 ///< Create server socket and listen
116 /**< Creates a new server socket, binds to \a address end
117 starts listening for new connections with a backlog of
118 \a backlog connections. It also enables reuseaddr().
120 \param[in] address address to listen on
121 \param[in] backlog size of the listen backlog */
122 /**< \note This member is implicitly called from the
123 ProtocolServerSocketHandle::ProtocolServerSocketHandle()
127 ///\name Abstract Interface Implementation
129 std::auto_ptr<SocketProtocol> clone() const;
134 typedef ProtocolClientSocketHandle<TCPv4SocketProtocol> TCPv4ClientSocketHandle;
135 typedef ProtocolServerSocketHandle<TCPv4SocketProtocol> TCPv4ServerSocketHandle;
137 typedef MakeSocketPolicy<
139 INet6AddressingPolicy
140 >::policy TCPv6Socket_Policy;
142 /** \brief IPv6 TCP Socket Protocol
144 \par Socket Handle typedefs:
145 \ref TCPv6ClientSocketHandle (ProtocolClientSocketHandle), \ref TCPv6ServerSocketHandle
146 (ProtocolServerSocketHandle)
148 \par Policy Interface:
149 ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(),
150 ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer(),
151 ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf()
156 TCPv6SocketProtocol provides an internet protocol stream socket based on the TCP protocol
159 This class is utilized as the protocol class of the ProtocolClientSocketHandle and
160 ProtocolServerSocketHandle via the Socket Handle typedefs above.
162 \see TCPv4SocketProtocol
164 class TCPv6SocketProtocol
165 : public ConcreteSocketProtocol<TCPv6Socket_Policy>,
168 public BSDSocketProtocol,
169 public AddressableBSDSocketProtocol,
170 public senf::pool_alloc_mixin<TCPv6SocketProtocol>
173 ///////////////////////////////////////////////////////////////////////////
174 // internal interface
176 ///\name Constructors
179 void init_client() const; ///< Create unconnected client socket
180 /**< \note This member is implicitly called from the
181 ProtocolClientSocketHandle::ProtocolClientSocketHandle()
183 void init_client(INet6SocketAddress const & address) const;
184 ///< Create client socket and connect
185 /**< Creates a new client socket and connects to the given
188 \param[in] address remote address to connect to */
189 /**< \note This member is implicitly called from the
190 ProtocolClientSocketHandle::ProtocolClientSocketHandle()
192 void init_server() const; ///< Create server socket
193 /**< \note This member is implicitly called from the
194 ProtocolServerSocketHandle::ProtocolServerSocketHandle()
196 void init_server(INet6SocketAddress const & address, unsigned backlog=1) const;
197 ///< Create server socket and listen
198 /**< Creates a new server socket, binds to \a address end
199 starts listening for new connections with a backlog of
200 \a backlog connections. It also enables reuseaddr().
202 \param[in] address address to listen on
203 \param[in] backlog size of the listen backlog */
204 /**< \note This member is implicitly called from the
205 ProtocolServerSocketHandle::ProtocolServerSocketHandle()
209 ///\name Abstract Interface Implementation
211 std::auto_ptr<SocketProtocol> clone() const;
216 typedef ProtocolClientSocketHandle<TCPv6SocketProtocol> TCPv6ClientSocketHandle;
217 typedef ProtocolServerSocketHandle<TCPv6SocketProtocol> TCPv6ServerSocketHandle;
223 ///////////////////////////////hh.e////////////////////////////////////////
224 //#include "TCPSocketHandle.cci"
225 //#include "TCPSocketHandle.ct"
226 //#include "TCPSocketHandle.cti"
233 // c-file-style: "senf"
234 // indent-tabs-mode: nil
235 // ispell-local-dictionary: "american"
236 // compile-command: "scons -u test"
237 // comment-column: 40