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 <senf/Utils/senfassert.hh>
33 #define prefix_ inline
34 ///////////////////////////////cci.p///////////////////////////////////////
36 ///////////////////////////////////////////////////////////////////////////
39 prefix_ senf::FileBody::FileBody(int fd)
43 prefix_ senf::FileHandle senf::FileBody::handle()
45 return FileHandle(ptr(this));
48 prefix_ int senf::FileBody::fd()
54 prefix_ void senf::FileBody::fd(int fd)
59 prefix_ bool senf::FileBody::eof()
65 prefix_ bool senf::FileBody::valid()
68 return fd_!=-1 && v_valid();
71 prefix_ bool senf::FileBody::readable()
74 return pollCheck(fd(),true,0);
77 prefix_ bool senf::FileBody::waitReadable(senf::ClockService::clock_type timeout)
80 return pollCheck(fd(), true,
81 (timeout==-1?-1:senf::ClockService::in_milliseconds(timeout)) );
84 prefix_ bool senf::FileBody::writeable()
87 return pollCheck(fd(),false,0);
90 prefix_ bool senf::FileBody::waitWriteable(senf::ClockService::clock_type timeout)
93 return pollCheck(fd(), false,
94 (timeout==-1?-1:senf::ClockService::in_milliseconds(timeout)) );
97 prefix_ bool senf::FileBody::oobReadable()
100 return pollCheck(fd(),true,0,true);
103 prefix_ bool senf::FileBody::waitOOBReadable(senf::ClockService::clock_type timeout)
106 return pollCheck(fd(), true,
107 (timeout==-1?-1:senf::ClockService::in_milliseconds(timeout)), true);
110 ///////////////////////////////////////////////////////////////////////////
113 prefix_ senf::FileBody & senf::FileHandle::body()
115 SENF_ASSERT(body_, "dereferencing in-valid() FileHandle");
119 prefix_ senf::FileBody const & senf::FileHandle::body()
122 SENF_ASSERT(body_, "dereferencing in-valid() FileHandle");
126 prefix_ void senf::FileHandle::close()
131 prefix_ void senf::FileHandle::terminate()
136 prefix_ bool senf::FileHandle::readable()
139 return body().readable();
142 prefix_ bool senf::FileHandle::waitReadable(senf::ClockService::clock_type timeout)
145 return body().waitReadable(timeout);
148 prefix_ bool senf::FileHandle::writeable()
151 return body().writeable();
154 prefix_ bool senf::FileHandle::waitWriteable(senf::ClockService::clock_type timeout)
157 return body().waitWriteable(timeout);
160 prefix_ bool senf::FileHandle::oobReadable()
163 return body().oobReadable();
166 prefix_ bool senf::FileHandle::waitOOBReadable(senf::ClockService::clock_type timeout)
169 return body().waitOOBReadable(timeout);
172 prefix_ bool senf::FileHandle::blocking()
175 return body().blocking();
178 prefix_ void senf::FileHandle::blocking(bool status)
180 body().blocking(status);
183 prefix_ bool senf::FileHandle::eof()
189 prefix_ bool senf::FileHandle::valid()
192 return body_ && body().valid();
195 prefix_ bool senf::FileHandle::boolean_test()
198 return valid() && !eof();
201 prefix_ int senf::FileHandle::fd()
207 prefix_ senf::FileHandle::FileHandle()
211 prefix_ senf::FileHandle::~FileHandle()
213 if (body_ && ! body().is_shared())
214 body().destroyClose();
217 prefix_ senf::FileHandle::FileHandle(std::auto_ptr<FileBody> body)
218 : body_(body.release())
221 prefix_ senf::FileHandle::FileHandle(FileBody::ptr body)
225 prefix_ senf::FileBody & senf::FileHandle::body(FileHandle & handle)
227 return handle.body();
230 prefix_ senf::FileBody const &
231 senf::FileHandle::body(FileHandle const & handle)
233 return handle.body();
236 prefix_ void senf::FileHandle::fd(int fd)
241 prefix_ senf::FileHandle::FileHandle
242 senf::FileHandle::cast_static(FileHandle handle)
247 prefix_ senf::FileHandle
248 senf::FileHandle::cast_dynamic(FileHandle handle)
253 prefix_ int senf::retrieve_filehandle(FileHandle handle)
258 ///////////////////////////////cci.e///////////////////////////////////////
265 // c-file-style: "senf"
266 // indent-tabs-mode: nil
267 // ispell-local-dictionary: "american"
268 // compile-command: "scons -u test"
269 // comment-column: 40