Renamed namespaces satcom::lib and satcom::pkf to senf
[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 // TODO: Move all not template-parameter dependent code into a
24 // non-template base class
25
26 #ifndef HH_ClientSocketHandle_
27 #define HH_ClientSocketHandle_ 1
28
29 // Custom includes
30 #include <boost/call_traits.hpp>
31 #include "SocketHandle.hh"
32
33 //#include "ClientSocketHandle.mpp"
34 ///////////////////////////////hh.p////////////////////////////////////////
35
36 namespace senf {
37
38
39     template <class Policy> class ServerSocketHandle;
40
41     /** \brief
42       */
43     template <class Policy>
44     class ClientSocketHandle
45         : public SocketHandle<Policy>
46     {
47     public:
48         ///////////////////////////////////////////////////////////////////////////
49         // Types
50
51         typedef typename Policy::AddressingPolicy::Address Address;
52         typedef typename boost::call_traits<Address>::param_type AddressParam;
53         typedef ServerSocketHandle<Policy> ServerSocketHandle;
54
55         ///////////////////////////////////////////////////////////////////////////
56         ///\name Structors and default members
57         ///@{
58
59         // no default constructor
60         // default copy constructor
61         // default copy assignment
62         // default destructor
63
64         // conversion constructors
65         template <class OtherPolicy>
66         ClientSocketHandle(ClientSocketHandle<OtherPolicy> other,
67                            typename SocketHandle<Policy>::template IsCompatible<OtherPolicy>::type * = 0);
68
69         template <class OtherPolicy>
70         typename SocketHandle<Policy>::template IsCompatible<OtherPolicy>::type const & 
71         operator=(ClientSocketHandle<OtherPolicy> other);
72
73         ///@}
74         ///////////////////////////////////////////////////////////////////////////
75
76         ///////////////////////////////////////////////////////////////////////////
77         ///\name reading and writing
78         ///@{
79
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);
84
85         // read from unconnected socket returning peer address
86         std::pair<std::string, Address> 
87                      readfrom     ();
88         void         readfrom     (std::string & buffer, Address & from);
89         unsigned     readfrom     (char * buffer, unsigned size, Address & from);
90
91         // write to connected socket
92         unsigned     write        (std::string const & data);
93         unsigned     write        (char const * buffer, unsigned size);
94
95         // write to unconnected socket
96         unsigned     writeto      (AddressParam addr, std::string const & data);
97         unsigned     writeto      (AddressParam addr, char const * buffer, unsigned size);
98
99         ///@}
100
101         ///////////////////////////////////////////////////////////////////////////
102         ///\name Addressing
103         ///@{
104
105         void         connect      (AddressParam addr);
106         void         bind         (AddressParam addr);
107
108         Address      peer         ();
109         void         peer         (Address & addr);
110         Address      local        ();
111         void         local        (Address & addr);
112
113         ///@}
114
115         ///////////////////////////////////////////////////////////////////////////
116         ///\name Buffering
117         ///@{
118         
119         unsigned     rcvbuf      ();
120         void         rcvbuf      (unsigned size);        
121         unsigned     sndbuf      ();
122         void         sndbuf      (unsigned size);
123         
124         ///@}
125         
126         static ClientSocketHandle cast_static(FileHandle handle);
127         static ClientSocketHandle cast_dynamic(FileHandle handle);
128
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);
132
133     protected:
134         ClientSocketHandle(FileHandle other, bool isChecked);
135         explicit ClientSocketHandle(std::auto_ptr<SocketProtocol> protocol,
136                                     int fd = -1);
137
138     private:
139         unsigned available();
140
141         friend class senf::ServerSocketHandle<Policy>;
142     };
143
144 }
145
146 ///////////////////////////////hh.e////////////////////////////////////////
147 //#include "ClientSocketHandle.cci"
148 #include "ClientSocketHandle.ct"
149 #include "ClientSocketHandle.cti"
150 #endif
151
152 \f
153 // Local Variables:
154 // mode: c++
155 // c-file-style: "senf"
156 // End: