Fix relative pathname handling in Doxyfiles
[senf.git] / Socket / ClientSocketHandle.hh
1 // $Id$
2 //
3 // Copyright (C) 2006 
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief senf::ClientSocketHandle public header
25  */
26
27 #ifndef HH_ClientSocketHandle_
28 #define HH_ClientSocketHandle_ 1
29
30 // Custom includes
31 #include <boost/call_traits.hpp>
32 #include "SocketHandle.hh"
33
34 //#include "ClientSocketHandle.mpp"
35 ///////////////////////////////hh.p////////////////////////////////////////
36
37 namespace senf {
38     
39     /// \addtogroup handle_group
40     /// @{
41     
42     template <class Policy> class ServerSocketHandle;
43
44     /** \brief Generic SocketHandle with client interface
45         
46         \todo Move all not template-parameter dependent code into a
47         non-template base class
48       */
49     template <class Policy>
50     class ClientSocketHandle
51         : public SocketHandle<Policy>
52     {
53     public:
54         ///////////////////////////////////////////////////////////////////////////
55         // Types
56
57         typedef typename Policy::AddressingPolicy::Address Address;
58         typedef typename boost::call_traits<Address>::param_type AddressParam;
59         typedef ServerSocketHandle<Policy> ServerSocketHandle;
60
61         ///////////////////////////////////////////////////////////////////////////
62         ///\name Structors and default members
63         ///@{
64
65         // no default constructor
66         // default copy constructor
67         // default copy assignment
68         // default destructor
69
70         // conversion constructors
71         template <class OtherPolicy>
72         ClientSocketHandle(ClientSocketHandle<OtherPolicy> other,
73                            typename SocketHandle<Policy>::template IsCompatible<OtherPolicy>::type * = 0);
74
75         template <class OtherPolicy>
76         typename SocketHandle<Policy>::template IsCompatible<OtherPolicy>::type const & 
77         operator=(ClientSocketHandle<OtherPolicy> other);
78
79         ///@}
80         ///////////////////////////////////////////////////////////////////////////
81
82         ///////////////////////////////////////////////////////////////////////////
83         ///\name reading and writing
84         ///@{
85
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);
90
91         // read from unconnected socket returning peer address
92         std::pair<std::string, Address> 
93                      readfrom     ();
94         void         readfrom     (std::string & buffer, Address & from);
95         unsigned     readfrom     (char * buffer, unsigned size, Address & from);
96
97         // write to connected socket
98         unsigned     write        (std::string const & data);
99         unsigned     write        (char const * buffer, unsigned size);
100
101         // write to unconnected socket
102         unsigned     writeto      (AddressParam addr, std::string const & data);
103         unsigned     writeto      (AddressParam addr, char const * buffer, unsigned size);
104
105         ///@}
106
107         ///////////////////////////////////////////////////////////////////////////
108         ///\name Addressing
109         ///@{
110
111         void         connect      (AddressParam addr);
112         void         bind         (AddressParam addr);
113
114         Address      peer         ();
115         void         peer         (Address & addr);
116         Address      local        ();
117         void         local        (Address & addr);
118
119         ///@}
120
121         ///////////////////////////////////////////////////////////////////////////
122         ///\name Buffering
123         ///@{
124         
125         unsigned     rcvbuf      ();
126         void         rcvbuf      (unsigned size);        
127         unsigned     sndbuf      ();
128         void         sndbuf      (unsigned size);
129         
130         ///@}
131         
132         static ClientSocketHandle cast_static(FileHandle handle);
133         static ClientSocketHandle cast_dynamic(FileHandle handle);
134
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);
138
139     protected:
140         ClientSocketHandle(FileHandle other, bool isChecked);
141         explicit ClientSocketHandle(std::auto_ptr<SocketProtocol> protocol,
142                                     int fd = -1);
143
144     private:
145         unsigned available();
146
147         friend class senf::ServerSocketHandle<Policy>;
148     };
149
150     /// @}
151 }
152
153 ///////////////////////////////hh.e////////////////////////////////////////
154 //#include "ClientSocketHandle.cci"
155 #include "ClientSocketHandle.ct"
156 #include "ClientSocketHandle.cti"
157 #endif
158
159 \f
160 // Local Variables:
161 // mode: c++
162 // c-file-style: "senf"
163 // End: