Socket: BUGFIX: Move incorrect v-function call out of FileBody destructor
[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 ///////////////////////////////////////////////////////////////////////////
97 // senf::FileHandle
98
99 prefix_ void senf::FileHandle::close()
100 {
101     body().close();
102 }
103
104 prefix_ void senf::FileHandle::terminate()
105 {
106     body().terminate();
107 }
108
109 prefix_ bool senf::FileHandle::readable()
110     const
111 {
112     return body().readable();
113 }
114
115 prefix_ void senf::FileHandle::waitReadable()
116     const
117 {
118     body().waitReadable();
119 }
120
121 prefix_ bool senf::FileHandle::writeable()
122     const
123 {
124     return body().writeable();
125 }
126
127 prefix_ void senf::FileHandle::waitWriteable()
128     const
129 {
130     body().waitWriteable();
131 }
132
133 prefix_ bool senf::FileHandle::blocking()
134     const
135 {
136     return body().blocking();
137 }
138
139 prefix_ void senf::FileHandle::blocking(bool status)
140 {
141     body().blocking(status);
142 }
143
144 prefix_ bool senf::FileHandle::eof()
145     const
146 {
147     return body().eof();
148 }
149
150 prefix_ bool senf::FileHandle::valid()
151     const
152 {
153     return body_ && body().valid();
154 }
155
156 prefix_ bool senf::FileHandle::boolean_test()
157     const
158 {
159     return valid() && !eof();
160 }
161
162 prefix_ int senf::FileHandle::fd()
163     const
164 {
165     return body().fd();
166 }
167
168 prefix_ senf::FileHandle::FileHandle()
169     : body_(0)
170 {}
171
172 prefix_ senf::FileHandle::~FileHandle()
173 {
174     if (body_ && ! body().is_shared())
175         body().destroyClose();
176 }
177
178 prefix_  senf::FileHandle::FileHandle(std::auto_ptr<FileBody> body)
179     : body_(body.release())
180 {}
181
182 prefix_ senf::FileHandle::FileHandle(FileBody::ptr body)
183     : body_(body)
184 {}
185
186 prefix_ senf::FileBody & senf::FileHandle::body()
187 {
188     SENF_ASSERT(body_);
189     return *body_;
190 }
191
192 prefix_ senf::FileBody const & senf::FileHandle::body()
193     const
194 {
195     SENF_ASSERT(body_);
196     return *body_;
197 }
198
199 prefix_ senf::FileBody & senf::FileHandle::body(FileHandle & handle)
200 {
201     return handle.body();
202 }
203
204 prefix_ senf::FileBody const &
205 senf::FileHandle::body(FileHandle const & handle)
206 {
207     return handle.body();
208 }
209
210 prefix_ void senf::FileHandle::fd(int fd)
211 {
212     body().fd(fd);
213 }
214
215 prefix_ senf::FileHandle::FileHandle
216 senf::FileHandle::cast_static(FileHandle handle)
217 {
218     return handle;
219 }
220
221 prefix_ senf::FileHandle
222 senf::FileHandle::cast_dynamic(FileHandle handle)
223 {
224     return handle;
225 }
226
227 prefix_ int senf::retrieve_filehandle(FileHandle handle)
228 {
229     return handle.fd();
230 }
231
232 ///////////////////////////////cci.e///////////////////////////////////////
233 #undef prefix_
234
235 \f
236 // Local Variables:
237 // mode: c++
238 // fill-column: 100
239 // c-file-style: "senf"
240 // indent-tabs-mode: nil
241 // ispell-local-dictionary: "american"
242 // compile-command: "scons -u test"
243 // comment-column: 40
244 // End: