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 \todo Move all not template-parameter dependent code into a
47 non-template base class
49 template <class Policy>
50 class ClientSocketHandle
51 : public SocketHandle<Policy>
54 ///////////////////////////////////////////////////////////////////////////
57 typedef typename Policy::AddressingPolicy::Address Address;
58 typedef typename boost::call_traits<Address>::param_type AddressParam;
59 typedef ServerSocketHandle<Policy> ServerSocketHandle;
61 ///////////////////////////////////////////////////////////////////////////
62 ///\name Structors and default members
65 // no default constructor
66 // default copy constructor
67 // default copy assignment
70 // conversion constructors
71 template <class OtherPolicy>
72 ClientSocketHandle(ClientSocketHandle<OtherPolicy> other,
73 typename SocketHandle<Policy>::template IsCompatible<OtherPolicy>::type * = 0);
75 template <class OtherPolicy>
76 typename SocketHandle<Policy>::template IsCompatible<OtherPolicy>::type const &
77 operator=(ClientSocketHandle<OtherPolicy> other);
80 ///////////////////////////////////////////////////////////////////////////
82 ///////////////////////////////////////////////////////////////////////////
83 ///\name reading and writing
86 // read from socket (connected or unconnected)
87 std::string read (unsigned limit=0);
88 void read (std::string & buffer, unsigned limit=0);
89 unsigned read (char * buffer, unsigned size);
91 // read from unconnected socket returning peer address
92 std::pair<std::string, Address>
94 void readfrom (std::string & buffer, Address & from);
95 unsigned readfrom (char * buffer, unsigned size, Address & from);
97 // write to connected socket
98 unsigned write (std::string const & data);
99 unsigned write (char const * buffer, unsigned size);
101 // write to unconnected socket
102 unsigned writeto (AddressParam addr, std::string const & data);
103 unsigned writeto (AddressParam addr, char const * buffer, unsigned size);
107 ///////////////////////////////////////////////////////////////////////////
111 void connect (AddressParam addr);
112 void bind (AddressParam addr);
115 void peer (Address & addr);
117 void local (Address & addr);
121 ///////////////////////////////////////////////////////////////////////////
126 void rcvbuf (unsigned size);
128 void sndbuf (unsigned size);
132 static ClientSocketHandle cast_static(FileHandle handle);
133 static ClientSocketHandle cast_dynamic(FileHandle handle);
135 // we need to override both since SocketHandle is *not* polymorphic
136 void state(SocketStateMap & map, unsigned lod=0);
137 std::string dumpState(unsigned lod=0);
140 ClientSocketHandle(FileHandle other, bool isChecked);
141 explicit ClientSocketHandle(std::auto_ptr<SocketProtocol> protocol,
145 unsigned available();
147 friend class senf::ServerSocketHandle<Policy>;
153 ///////////////////////////////hh.e////////////////////////////////////////
154 //#include "ClientSocketHandle.cci"
155 #include "ClientSocketHandle.ct"
156 #include "ClientSocketHandle.cti"
162 // c-file-style: "senf"