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.
23 #ifndef HH_ClientSocketHandle_
24 #define HH_ClientSocketHandle_ 1
27 #include <boost/call_traits.hpp>
28 #include "SocketHandle.hh"
30 //#include "ClientSocketHandle.mpp"
31 ///////////////////////////////hh.p////////////////////////////////////////
35 /// \addtogroup handle_group
38 template <class Policy> class ServerSocketHandle;
42 \todo Move all not template-parameter dependent code into a
43 non-template base class
45 template <class Policy>
46 class ClientSocketHandle
47 : public SocketHandle<Policy>
50 ///////////////////////////////////////////////////////////////////////////
53 typedef typename Policy::AddressingPolicy::Address Address;
54 typedef typename boost::call_traits<Address>::param_type AddressParam;
55 typedef ServerSocketHandle<Policy> ServerSocketHandle;
57 ///////////////////////////////////////////////////////////////////////////
58 ///\name Structors and default members
61 // no default constructor
62 // default copy constructor
63 // default copy assignment
66 // conversion constructors
67 template <class OtherPolicy>
68 ClientSocketHandle(ClientSocketHandle<OtherPolicy> other,
69 typename SocketHandle<Policy>::template IsCompatible<OtherPolicy>::type * = 0);
71 template <class OtherPolicy>
72 typename SocketHandle<Policy>::template IsCompatible<OtherPolicy>::type const &
73 operator=(ClientSocketHandle<OtherPolicy> other);
76 ///////////////////////////////////////////////////////////////////////////
78 ///////////////////////////////////////////////////////////////////////////
79 ///\name reading and writing
82 // read from socket (connected or unconnected)
83 std::string read (unsigned limit=0);
84 void read (std::string & buffer, unsigned limit=0);
85 unsigned read (char * buffer, unsigned size);
87 // read from unconnected socket returning peer address
88 std::pair<std::string, Address>
90 void readfrom (std::string & buffer, Address & from);
91 unsigned readfrom (char * buffer, unsigned size, Address & from);
93 // write to connected socket
94 unsigned write (std::string const & data);
95 unsigned write (char const * buffer, unsigned size);
97 // write to unconnected socket
98 unsigned writeto (AddressParam addr, std::string const & data);
99 unsigned writeto (AddressParam addr, char const * buffer, unsigned size);
103 ///////////////////////////////////////////////////////////////////////////
107 void connect (AddressParam addr);
108 void bind (AddressParam addr);
111 void peer (Address & addr);
113 void local (Address & addr);
117 ///////////////////////////////////////////////////////////////////////////
122 void rcvbuf (unsigned size);
124 void sndbuf (unsigned size);
128 static ClientSocketHandle cast_static(FileHandle handle);
129 static ClientSocketHandle cast_dynamic(FileHandle handle);
131 // we need to override both since SocketHandle is *not* polymorphic
132 void state(SocketStateMap & map, unsigned lod=0);
133 std::string dumpState(unsigned lod=0);
136 ClientSocketHandle(FileHandle other, bool isChecked);
137 explicit ClientSocketHandle(std::auto_ptr<SocketProtocol> protocol,
141 unsigned available();
143 friend class senf::ServerSocketHandle<Policy>;
149 ///////////////////////////////hh.e////////////////////////////////////////
150 //#include "ClientSocketHandle.cci"
151 #include "ClientSocketHandle.ct"
152 #include "ClientSocketHandle.cti"
158 // c-file-style: "senf"