fixes for g++ 4.5 (some members returned "the constructor, not the type")
[senf.git] / senf / Socket / FileHandle.cci
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.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 FileHandle inline non-template implementation
25  */
26
27 //#include "FileHandle.ih"
28
29 // Custom includes
30 #include <senf/Utils/senfassert.hh>
31 #include <errno.h>
32
33 #define prefix_ inline
34 //-/////////////////////////////////////////////////////////////////////////////////////////////////
35
36 //-/////////////////////////////////////////////////////////////////////////////////////////////////
37 // senf::FileBody
38
39 prefix_ senf::FileBody::FileBody(int fd)
40     : fd_(fd)
41 {}
42
43 prefix_ senf::FileHandle senf::FileBody::handle()
44 {
45     return FileHandle(ptr(this));
46 }
47
48 prefix_ int senf::FileBody::fd()
49     const
50 {
51     return fd_;
52 }
53
54 prefix_ void senf::FileBody::fd(int fd)
55 {
56     fd_ = fd;
57 }
58
59 prefix_ bool senf::FileBody::eof()
60     const
61 {
62     return v_eof();
63 }
64
65 prefix_ bool senf::FileBody::valid()
66     const
67 {
68     return fd_!=-1 && v_valid();
69 }
70
71 prefix_ bool senf::FileBody::readable()
72     const
73 {
74     return pollCheck(fd(),true,0);
75 }
76
77 prefix_ bool senf::FileBody::waitReadable(senf::ClockService::clock_type timeout)
78     const
79 {
80     return pollCheck(fd(), true,
81                      (timeout==-1?-1:senf::ClockService::in_milliseconds(timeout)) );
82 }
83
84 prefix_ bool senf::FileBody::writeable()
85     const
86 {
87     return pollCheck(fd(),false,0);
88 }
89
90 prefix_ bool senf::FileBody::waitWriteable(senf::ClockService::clock_type timeout)
91     const
92 {
93     return pollCheck(fd(), false,
94                      (timeout==-1?-1:senf::ClockService::in_milliseconds(timeout)) );
95 }
96
97 prefix_ bool senf::FileBody::oobReadable()
98     const
99 {
100     return pollCheck(fd(),true,0,true);
101 }
102
103 prefix_ bool senf::FileBody::waitOOBReadable(senf::ClockService::clock_type timeout)
104     const
105 {
106     return pollCheck(fd(), true,
107                      (timeout==-1?-1:senf::ClockService::in_milliseconds(timeout)), true);
108 }
109
110 //-/////////////////////////////////////////////////////////////////////////////////////////////////
111 // senf::FileHandle
112
113 prefix_ senf::FileBody & senf::FileHandle::body()
114 {
115     SENF_ASSERT(body_, "dereferencing in-valid() FileHandle");
116     return *body_;
117 }
118
119 prefix_ senf::FileBody const & senf::FileHandle::body()
120     const
121 {
122     SENF_ASSERT(body_, "dereferencing in-valid() FileHandle");
123     return *body_;
124 }
125
126 prefix_ void senf::FileHandle::close()
127 {
128     body().close();
129 }
130
131 prefix_ void senf::FileHandle::terminate()
132 {
133     body().terminate();
134 }
135
136 prefix_ bool senf::FileHandle::readable()
137     const
138 {
139     return body().readable();
140 }
141
142 prefix_ bool senf::FileHandle::waitReadable(senf::ClockService::clock_type timeout)
143     const
144 {
145     return body().waitReadable(timeout);
146 }
147
148 prefix_ bool senf::FileHandle::writeable()
149     const
150 {
151     return body().writeable();
152 }
153
154 prefix_ bool senf::FileHandle::waitWriteable(senf::ClockService::clock_type timeout)
155     const
156 {
157     return body().waitWriteable(timeout);
158 }
159
160 prefix_ bool senf::FileHandle::oobReadable()
161     const
162 {
163     return body().oobReadable();
164 }
165
166 prefix_ bool senf::FileHandle::waitOOBReadable(senf::ClockService::clock_type timeout)
167     const
168 {
169     return body().waitOOBReadable(timeout);
170 }
171
172 prefix_ bool senf::FileHandle::blocking()
173     const
174 {
175     return body().blocking();
176 }
177
178 prefix_ void senf::FileHandle::blocking(bool status)
179 {
180     body().blocking(status);
181 }
182
183 prefix_ bool senf::FileHandle::eof()
184     const
185 {
186     return body().eof();
187 }
188
189 prefix_ bool senf::FileHandle::valid()
190     const
191 {
192     return body_ && body().valid();
193 }
194
195 prefix_ bool senf::FileHandle::boolean_test()
196     const
197 {
198     return valid() && !eof();
199 }
200
201 prefix_ int senf::FileHandle::fd()
202     const
203 {
204     return body().fd();
205 }
206
207 prefix_ senf::FileHandle::FileHandle()
208     : body_(0)
209 {}
210
211 prefix_ senf::FileHandle::~FileHandle()
212 {
213     if (body_ && ! body().is_shared())
214         body().destroyClose();
215 }
216
217 prefix_  senf::FileHandle::FileHandle(std::auto_ptr<FileBody> body)
218     : body_(body.release())
219 {}
220
221 prefix_ senf::FileHandle::FileHandle(FileBody::ptr body)
222     : body_(body)
223 {}
224
225 prefix_ senf::FileBody & senf::FileHandle::body(FileHandle & handle)
226 {
227     return handle.body();
228 }
229
230 prefix_ senf::FileBody const & senf::FileHandle::body(FileHandle const & handle)
231 {
232     return handle.body();
233 }
234
235 prefix_ void senf::FileHandle::fd(int fd)
236 {
237     body().fd(fd);
238 }
239
240 prefix_ senf::FileHandle senf::FileHandle::cast_static(FileHandle handle)
241 {
242     return handle;
243 }
244
245 prefix_ senf::FileHandle senf::FileHandle::cast_dynamic(FileHandle handle)
246 {
247     return handle;
248 }
249
250 prefix_ int senf::retrieve_filehandle(FileHandle handle)
251 {
252     return handle.fd();
253 }
254
255 //-/////////////////////////////////////////////////////////////////////////////////////////////////
256 #undef prefix_
257
258 \f
259 // Local Variables:
260 // mode: c++
261 // fill-column: 100
262 // c-file-style: "senf"
263 // indent-tabs-mode: nil
264 // ispell-local-dictionary: "american"
265 // compile-command: "scons -u test"
266 // comment-column: 40
267 // End: