5cbfce4cc63e54bf082a2b516aad50a908b14e33
[senf.git] / 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);
76 }
77
78 prefix_ void senf::FileBody::waitReadable()
79     const
80 {
81     pollCheck(fd(),true,true);
82 }
83
84 prefix_ bool senf::FileBody::writeable()
85     const
86 {
87     return pollCheck(fd(),false);
88 }
89
90 prefix_ void senf::FileBody::waitWriteable()
91     const
92 {
93     pollCheck(fd(),false,true);
94 }
95
96 prefix_ bool senf::FileBody::oobReadable()
97     const
98 {
99     return pollCheck(fd(),true,false,true);
100 }
101
102 prefix_ void senf::FileBody::waitOOBReadable()
103     const
104 {
105     pollCheck(fd(),true,true,true);
106 }
107
108 ///////////////////////////////////////////////////////////////////////////
109 // senf::FileHandle
110
111 prefix_ senf::FileBody & senf::FileHandle::body()
112 {
113     SENF_ASSERT(body_);
114     return *body_;
115 }
116
117 prefix_ senf::FileBody const & senf::FileHandle::body()
118     const
119 {
120     SENF_ASSERT(body_);
121     return *body_;
122 }
123
124 prefix_ void senf::FileHandle::close()
125 {
126     body().close();
127 }
128
129 prefix_ void senf::FileHandle::terminate()
130 {
131     body().terminate();
132 }
133
134 prefix_ bool senf::FileHandle::readable()
135     const
136 {
137     return body().readable();
138 }
139
140 prefix_ void senf::FileHandle::waitReadable()
141     const
142 {
143     body().waitReadable();
144 }
145
146 prefix_ bool senf::FileHandle::writeable()
147     const
148 {
149     return body().writeable();
150 }
151
152 prefix_ void senf::FileHandle::waitWriteable()
153     const
154 {
155     body().waitWriteable();
156 }
157
158 prefix_ bool senf::FileHandle::oobReadable()
159     const
160 {
161     return body().oobReadable();
162 }
163
164 prefix_ void senf::FileHandle::waitOOBReadable()
165     const
166 {
167     body().waitOOBReadable();
168 }
169
170 prefix_ bool senf::FileHandle::blocking()
171     const
172 {
173     return body().blocking();
174 }
175
176 prefix_ void senf::FileHandle::blocking(bool status)
177 {
178     body().blocking(status);
179 }
180
181 prefix_ bool senf::FileHandle::eof()
182     const
183 {
184     return body().eof();
185 }
186
187 prefix_ bool senf::FileHandle::valid()
188     const
189 {
190     return body_ && body().valid();
191 }
192
193 prefix_ bool senf::FileHandle::boolean_test()
194     const
195 {
196     return valid() && !eof();
197 }
198
199 prefix_ int senf::FileHandle::fd()
200     const
201 {
202     return body().fd();
203 }
204
205 prefix_ senf::FileHandle::FileHandle()
206     : body_(0)
207 {}
208
209 prefix_ senf::FileHandle::~FileHandle()
210 {
211     if (body_ && ! body().is_shared())
212         body().destroyClose();
213 }
214
215 prefix_  senf::FileHandle::FileHandle(std::auto_ptr<FileBody> body)
216     : body_(body.release())
217 {}
218
219 prefix_ senf::FileHandle::FileHandle(FileBody::ptr body)
220     : body_(body)
221 {}
222
223 prefix_ senf::FileBody & senf::FileHandle::body(FileHandle & handle)
224 {
225     return handle.body();
226 }
227
228 prefix_ senf::FileBody const &
229 senf::FileHandle::body(FileHandle const & handle)
230 {
231     return handle.body();
232 }
233
234 prefix_ void senf::FileHandle::fd(int fd)
235 {
236     body().fd(fd);
237 }
238
239 prefix_ senf::FileHandle::FileHandle
240 senf::FileHandle::cast_static(FileHandle handle)
241 {
242     return handle;
243 }
244
245 prefix_ senf::FileHandle
246 senf::FileHandle::cast_dynamic(FileHandle handle)
247 {
248     return handle;
249 }
250
251 prefix_ int senf::retrieve_filehandle(FileHandle handle)
252 {
253     return handle.fd();
254 }
255
256 ///////////////////////////////cci.e///////////////////////////////////////
257 #undef prefix_
258
259 \f
260 // Local Variables:
261 // mode: c++
262 // fill-column: 100
263 // c-file-style: "senf"
264 // indent-tabs-mode: nil
265 // ispell-local-dictionary: "american"
266 // compile-command: "scons -u test"
267 // comment-column: 40
268 // End: