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