4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
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.
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.
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.
24 \brief FileHandle inline non-template implementation
27 //#include "FileHandle.ih"
30 #include "../Utils/senfassert.hh"
32 #include "../Utils/Exception.hh"
34 #define prefix_ inline
35 ///////////////////////////////cci.p///////////////////////////////////////
37 ///////////////////////////////////////////////////////////////////////////
40 prefix_ senf::FileBody::FileBody(int fd)
44 prefix_ senf::FileHandle senf::FileBody::handle()
46 return FileHandle(ptr(this));
49 prefix_ int senf::FileBody::fd()
55 prefix_ void senf::FileBody::fd(int fd)
60 prefix_ bool senf::FileBody::eof()
66 prefix_ bool senf::FileBody::valid()
69 return fd_!=-1 && v_valid();
72 prefix_ bool senf::FileBody::readable()
75 return pollCheck(fd(),true,0);
78 prefix_ bool senf::FileBody::waitReadable(senf::ClockService::clock_type timeout)
81 return pollCheck(fd(), true,
82 (timeout==-1?-1:senf::ClockService::in_milliseconds(timeout)) );
85 prefix_ bool senf::FileBody::writeable()
88 return pollCheck(fd(),false,0);
91 prefix_ bool senf::FileBody::waitWriteable(senf::ClockService::clock_type timeout)
94 return pollCheck(fd(), false,
95 (timeout==-1?-1:senf::ClockService::in_milliseconds(timeout)) );
98 prefix_ bool senf::FileBody::oobReadable()
101 return pollCheck(fd(),true,0,true);
104 prefix_ bool senf::FileBody::waitOOBReadable(senf::ClockService::clock_type timeout)
107 return pollCheck(fd(), true,
108 (timeout==-1?-1:senf::ClockService::in_milliseconds(timeout)), true);
111 ///////////////////////////////////////////////////////////////////////////
114 prefix_ senf::FileBody & senf::FileHandle::body()
120 prefix_ senf::FileBody const & senf::FileHandle::body()
127 prefix_ void senf::FileHandle::close()
132 prefix_ void senf::FileHandle::terminate()
137 prefix_ bool senf::FileHandle::readable()
140 return body().readable();
143 prefix_ bool senf::FileHandle::waitReadable(senf::ClockService::clock_type timeout)
146 return body().waitReadable(timeout);
149 prefix_ bool senf::FileHandle::writeable()
152 return body().writeable();
155 prefix_ bool senf::FileHandle::waitWriteable(senf::ClockService::clock_type timeout)
158 return body().waitWriteable(timeout);
161 prefix_ bool senf::FileHandle::oobReadable()
164 return body().oobReadable();
167 prefix_ bool senf::FileHandle::waitOOBReadable(senf::ClockService::clock_type timeout)
170 return body().waitOOBReadable(timeout);
173 prefix_ bool senf::FileHandle::blocking()
176 return body().blocking();
179 prefix_ void senf::FileHandle::blocking(bool status)
181 body().blocking(status);
184 prefix_ bool senf::FileHandle::eof()
190 prefix_ bool senf::FileHandle::valid()
193 return body_ && body().valid();
196 prefix_ bool senf::FileHandle::boolean_test()
199 return valid() && !eof();
202 prefix_ int senf::FileHandle::fd()
208 prefix_ senf::FileHandle::FileHandle()
212 prefix_ senf::FileHandle::~FileHandle()
214 if (body_ && ! body().is_shared())
215 body().destroyClose();
218 prefix_ senf::FileHandle::FileHandle(std::auto_ptr<FileBody> body)
219 : body_(body.release())
222 prefix_ senf::FileHandle::FileHandle(FileBody::ptr body)
226 prefix_ senf::FileBody & senf::FileHandle::body(FileHandle & handle)
228 return handle.body();
231 prefix_ senf::FileBody const &
232 senf::FileHandle::body(FileHandle const & handle)
234 return handle.body();
237 prefix_ void senf::FileHandle::fd(int fd)
242 prefix_ senf::FileHandle::FileHandle
243 senf::FileHandle::cast_static(FileHandle handle)
248 prefix_ senf::FileHandle
249 senf::FileHandle::cast_dynamic(FileHandle handle)
254 prefix_ int senf::retrieve_filehandle(FileHandle handle)
259 ///////////////////////////////cci.e///////////////////////////////////////
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