4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <stefan.bund@fokus.fraunhofer.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/BufferingPolicy.hh"
42 #include "../../../Socket/ProtocolClientSocketHandle.hh"
43 #include "../../../Socket/ProtocolServerSocketHandle.hh"
45 //#include "TCPSocketHandle.mpp"
46 ///////////////////////////////hh.p////////////////////////////////////////
50 /// \addtogroup concrete_protocol_group
53 typedef MakeSocketPolicy<
54 INet4AddressingPolicy,
56 ConnectedCommunicationPolicy,
60 >::policy TCPv4Socket_Policy; ///< Socket Policy of the TCPv4 Protocol
62 /** \brief IPv4 TCP Socket Protocol
64 \par Socket Handle typedefs:
65 \ref TCPv4ClientSocketHandle (ProtocolClientSocketHandle), \ref TCPv4ServerSocketHandle
66 (ProtocolServerSocketHandle)
68 \par Policy Interface:
69 ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(),
70 ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer(),
71 ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf()
76 TCPv4SocketProtocol provides an internet protocol stream socket based on the TCP protocol
79 This class is utilized as the protocol class of the ProtocolClientSocketHandle and
80 ProtocolServerSocketHandle via the Socket Handle typedefs above.
82 \see TCPv6SocketProtocol
84 class TCPv4SocketProtocol
85 : public ConcreteSocketProtocol<TCPv4Socket_Policy>,
88 public BSDSocketProtocol,
89 public AddressableBSDSocketProtocol,
90 public senf::pool_alloc_mixin<TCPv4SocketProtocol>
93 ///////////////////////////////////////////////////////////////////////////
99 void init_client() const; ///< Create unconnected client socket
100 /**< \note This member is implicitly called from the
101 ProtocolClientSocketHandle::ProtocolClientSocketHandle()
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
108 \param[in] address remote address to connect to */
109 /**< \note This member is implicitly called from the
110 ProtocolClientSocketHandle::ProtocolClientSocketHandle()
112 void init_server() const; ///< Create server socket
113 /**< \note This member is implicitly called from the
114 ProtocolServerSocketHandle::ProtocolServerSocketHandle()
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().
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()
129 ///\name Abstract Interface Implementation
131 std::auto_ptr<SocketProtocol> clone() const;
136 typedef ProtocolClientSocketHandle<TCPv4SocketProtocol> TCPv4ClientSocketHandle;
137 typedef ProtocolServerSocketHandle<TCPv4SocketProtocol> TCPv4ServerSocketHandle;
139 typedef MakeSocketPolicy<
141 INet6AddressingPolicy
142 >::policy TCPv6Socket_Policy;
144 /** \brief IPv6 TCP Socket Protocol
146 \par Socket Handle typedefs:
147 \ref TCPv6ClientSocketHandle (ProtocolClientSocketHandle), \ref TCPv6ServerSocketHandle
148 (ProtocolServerSocketHandle)
150 \par Policy Interface:
151 ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(),
152 ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer(),
153 ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf()
158 TCPv6SocketProtocol provides an internet protocol stream socket based on the TCP protocol
161 This class is utilized as the protocol class of the ProtocolClientSocketHandle and
162 ProtocolServerSocketHandle via the Socket Handle typedefs above.
164 \see TCPv4SocketProtocol
166 class TCPv6SocketProtocol
167 : public ConcreteSocketProtocol<TCPv6Socket_Policy>,
170 public BSDSocketProtocol,
171 public AddressableBSDSocketProtocol,
172 public senf::pool_alloc_mixin<TCPv6SocketProtocol>
175 ///////////////////////////////////////////////////////////////////////////
176 // internal interface
178 ///\name Constructors
181 void init_client() const; ///< Create unconnected client socket
182 /**< \note This member is implicitly called from the
183 ProtocolClientSocketHandle::ProtocolClientSocketHandle()
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
190 \param[in] address remote address to connect to */
191 /**< \note This member is implicitly called from the
192 ProtocolClientSocketHandle::ProtocolClientSocketHandle()
194 void init_server() const; ///< Create server socket
195 /**< \note This member is implicitly called from the
196 ProtocolServerSocketHandle::ProtocolServerSocketHandle()
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().
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()
211 ///\name Abstract Interface Implementation
213 std::auto_ptr<SocketProtocol> clone() const;
218 typedef ProtocolClientSocketHandle<TCPv6SocketProtocol> TCPv6ClientSocketHandle;
219 typedef ProtocolServerSocketHandle<TCPv6SocketProtocol> TCPv6ServerSocketHandle;
225 ///////////////////////////////hh.e////////////////////////////////////////
226 //#include "TCPSocketHandle.cci"
227 //#include "TCPSocketHandle.ct"
228 //#include "TCPSocketHandle.cti"
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