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 senf::ClientSocketHandle public header
27 #ifndef HH_ClientSocketHandle_
28 #define HH_ClientSocketHandle_ 1
31 #include <boost/call_traits.hpp>
32 #include "SocketHandle.hh"
34 //#include "ClientSocketHandle.mpp"
35 ///////////////////////////////hh.p////////////////////////////////////////
39 /// \addtogroup handle_group
42 template <class Policy> class ServerSocketHandle;
44 /** \brief Generic SocketHandle with client interface
46 This class provides the client side policy interface of the
47 socket abstraction. ClientSocketHandle defines the complete
48 policy interface. It does not implement any functionality
49 itself however. All calls are forward to the following policy
53 <tr><th>ClientSocketHandle member</th> <th>Policy member</th></tr>
54 <tr><td>read()</td> <td>ReadPolicy::read (\ref senf::ReadPolicyBase)</td></tr>
55 <tr><td>readfrom()</td> <td>ReadPolicy::readfrom (\ref senf::ReadPolicyBase)</td></tr>
56 <tr><td>write()</td> <td>WritePolicy::write (\ref senf::WritePolicyBase)</td></tr>
57 <tr><td>writeto()</td> <td>WritePolicy::writeto (\ref senf::WritePolicyBase)</td></tr>
58 <tr><td>connect()</td> <td>AddressingPolicy::connect (\ref senf::AddressingPolicyBase)</td></tr>
59 <tr><td>bind()</td> <td>AddressingPolicy::bind (\ref senf::AddressingPolicyBase)</td></tr>
60 <tr><td>peer()</td> <td>AddressingPolicy::peer (\ref senf::AddressingPolicyBase)</td></tr>
61 <tr><td>local()</td> <td>AddressingPolicy::local (\ref senf::AddressingPolicyBase)</td></tr>
62 <tr><td>rcvbuf()</td> <td>BufferingPolicy::sndbuf (\ref senf::BufferingPolicyBase)</td></tr>
63 <tr><td>sndbuf()</td> <td>BufferingPolicy::rcvbuf (\ref senf::BufferingPolicyBase)</td></tr>
66 It is important to note, that not all members are always
67 accessible. Which are depends on the \c Policy template
68 argument. If any of the policy axis is left unspecified the
69 corresponding members will not be callable (you will get a
70 compile time error). Even if every policy axis is defined,
71 some members might (and will) not exist depending on the exact
72 policy. To find out, which members are available, you have to
73 check the documentation of the policy classes. You can also
74 find a summary of all active members in the leaf protocol
77 \todo Move all not template-parameter dependent code into a
78 non-template base class
80 \idea Give SocketHandle (and therefore ClientSocketHandle and
81 ServerSocketHandle) a \c protocol() template member and an
82 additional template arg \c Policies. This arg should be a
83 typelist of Poclicy classes which can be accessed. You use
84 protocol<ProtocolClass>() to access a protocol class. \c
85 Policies can of course be underspecified or even empty.
87 \idea add more flexible read/write members for a)
88 boost::arrays and arrays of other types b) std::vector (which
89 uses contiguous memory ..) c) other random-access containers
90 (we should use some configurable trait class to identify
91 containers with contiguous storage). Probably we should just
92 use a generic Boost.Range interface. Here we again come to the
93 point: make all except the most basic members be non-member
94 algorithms ? this would make the configuration of such
95 extenden members more flexible.
97 \see \ref policy_group
100 template <class Policy>
101 class ClientSocketHandle
102 : public SocketHandle<Policy>
105 ///////////////////////////////////////////////////////////////////////////
108 typedef typename Policy::AddressingPolicy::Address Address;
109 typedef typename boost::call_traits<Address>::param_type AddressParam;
110 typedef ServerSocketHandle<Policy> ServerSocketHandle;
112 ///////////////////////////////////////////////////////////////////////////
113 ///\name Structors and default members
116 // no default constructor
117 // default copy constructor
118 // default copy assignment
119 // default destructor
121 // conversion constructors
122 template <class OtherPolicy>
123 ClientSocketHandle(ClientSocketHandle<OtherPolicy> other,
124 typename SocketHandle<Policy>::template IsCompatible<OtherPolicy>::type * = 0);
126 template <class OtherPolicy>
127 typename SocketHandle<Policy>::template IsCompatible<OtherPolicy>::type const &
128 operator=(ClientSocketHandle<OtherPolicy> other);
131 ///////////////////////////////////////////////////////////////////////////
133 ///////////////////////////////////////////////////////////////////////////
134 ///\name Reading and Writing
137 // read from socket (connected or unconnected)
138 std::string read (unsigned limit=0);
139 void read (std::string & buffer, unsigned limit=0);
140 unsigned read (char * buffer, unsigned size);
142 // read from unconnected socket returning peer address
143 std::pair<std::string, Address>
145 void readfrom (std::string & buffer, Address & from);
146 unsigned readfrom (char * buffer, unsigned size, Address & from);
148 // write to connected socket
149 unsigned write (std::string const & data);
150 unsigned write (char const * buffer, unsigned size);
152 // write to unconnected socket
153 unsigned writeto (AddressParam addr, std::string const & data);
154 unsigned writeto (AddressParam addr, char const * buffer, unsigned size);
158 ///////////////////////////////////////////////////////////////////////////
162 void connect (AddressParam addr);
163 void bind (AddressParam addr);
166 void peer (Address & addr);
168 void local (Address & addr);
172 ///////////////////////////////////////////////////////////////////////////
177 void rcvbuf (unsigned size);
179 void sndbuf (unsigned size);
183 static ClientSocketHandle cast_static(FileHandle handle);
184 static ClientSocketHandle cast_dynamic(FileHandle handle);
186 // we need to override both since SocketHandle is *not* polymorphic
187 void state(SocketStateMap & map, unsigned lod=0);
188 std::string dumpState(unsigned lod=0);
191 ClientSocketHandle(FileHandle other, bool isChecked);
192 explicit ClientSocketHandle(std::auto_ptr<SocketProtocol> protocol,
196 unsigned available();
198 friend class senf::ServerSocketHandle<Policy>;
204 ///////////////////////////////hh.e////////////////////////////////////////
205 //#include "ClientSocketHandle.cci"
206 #include "ClientSocketHandle.ct"
207 #include "ClientSocketHandle.cti"
213 // c-file-style: "senf"