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 // TODO: Move all not template-parameter dependent code into a
24 // non-template base class
26 #ifndef HH_ClientSocketHandle_
27 #define HH_ClientSocketHandle_ 1
30 #include <boost/call_traits.hpp>
31 #include "SocketHandle.hh"
33 //#include "ClientSocketHandle.mpp"
34 ///////////////////////////////hh.p////////////////////////////////////////
39 template <class Policy> class ServerSocketHandle;
43 template <class Policy>
44 class ClientSocketHandle
45 : public SocketHandle<Policy>
48 ///////////////////////////////////////////////////////////////////////////
51 typedef typename Policy::AddressingPolicy::Address Address;
52 typedef typename boost::call_traits<Address>::param_type AddressParam;
53 typedef ServerSocketHandle<Policy> ServerSocketHandle;
55 ///////////////////////////////////////////////////////////////////////////
56 ///\name Structors and default members
59 // no default constructor
60 // default copy constructor
61 // default copy assignment
64 // conversion constructors
65 template <class OtherPolicy>
66 ClientSocketHandle(ClientSocketHandle<OtherPolicy> other,
67 typename SocketHandle<Policy>::template IsCompatible<OtherPolicy>::type * = 0);
69 template <class OtherPolicy>
70 typename SocketHandle<Policy>::template IsCompatible<OtherPolicy>::type const &
71 operator=(ClientSocketHandle<OtherPolicy> other);
74 ///////////////////////////////////////////////////////////////////////////
76 ///////////////////////////////////////////////////////////////////////////
77 ///\name reading and writing
80 // read from socket (connected or unconnected)
81 std::string read (unsigned limit=0);
82 void read (std::string & buffer, unsigned limit=0);
83 unsigned read (char * buffer, unsigned size);
85 // read from unconnected socket returning peer address
86 std::pair<std::string, Address>
88 void readfrom (std::string & buffer, Address & from);
89 unsigned readfrom (char * buffer, unsigned size, Address & from);
91 // write to connected socket
92 unsigned write (std::string const & data);
93 unsigned write (char const * buffer, unsigned size);
95 // write to unconnected socket
96 unsigned writeto (AddressParam addr, std::string const & data);
97 unsigned writeto (AddressParam addr, char const * buffer, unsigned size);
101 ///////////////////////////////////////////////////////////////////////////
105 void connect (AddressParam addr);
106 void bind (AddressParam addr);
109 void peer (Address & addr);
111 void local (Address & addr);
115 ///////////////////////////////////////////////////////////////////////////
120 void rcvbuf (unsigned size);
122 void sndbuf (unsigned size);
126 static ClientSocketHandle cast_static(FileHandle handle);
127 static ClientSocketHandle cast_dynamic(FileHandle handle);
129 // we need to override both since SocketHandle is *not* polymorphic
130 void state(SocketStateMap & map, unsigned lod=0);
131 std::string dumpState(unsigned lod=0);
134 ClientSocketHandle(FileHandle other, bool isChecked);
135 explicit ClientSocketHandle(std::auto_ptr<SocketProtocol> protocol,
139 unsigned available();
141 friend class satcom::lib::ServerSocketHandle<Policy>;
146 ///////////////////////////////hh.e////////////////////////////////////////
147 //#include "ClientSocketHandle.cci"
148 #include "ClientSocketHandle.ct"
149 #include "ClientSocketHandle.cti"
155 // c-file-style: "satcom"