Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • Directories
  • File List
  • File Members

FileHandle.cci

Go to the documentation of this file.
00001 // $Id: FileHandle.cci 1770 2011-02-14 10:36:53Z tho $
00002 //
00003 // Copyright (C) 2006
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00027 //#include "FileHandle.ih"
00028 
00029 // Custom includes
00030 #include <senf/Utils/senfassert.hh>
00031 #include <errno.h>
00032 
00033 #define prefix_ inline
00034 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00035 
00036 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00037 // senf::FileBody
00038 
00039 prefix_ senf::FileBody::FileBody(int fd)
00040     : fd_(fd)
00041 {}
00042 
00043 prefix_ senf::FileHandle senf::FileBody::handle()
00044 {
00045     return FileHandle(ptr(this));
00046 }
00047 
00048 prefix_ int senf::FileBody::fd()
00049     const
00050 {
00051     return fd_;
00052 }
00053 
00054 prefix_ void senf::FileBody::fd(int fd)
00055 {
00056     fd_ = fd;
00057 }
00058 
00059 prefix_ bool senf::FileBody::eof()
00060     const
00061 {
00062     return v_eof();
00063 }
00064 
00065 prefix_ bool senf::FileBody::valid()
00066     const
00067 {
00068     return fd_!=-1 && v_valid();
00069 }
00070 
00071 prefix_ bool senf::FileBody::readable()
00072     const
00073 {
00074     return pollCheck(fd(),true,0);
00075 }
00076 
00077 prefix_ bool senf::FileBody::waitReadable(senf::ClockService::clock_type timeout)
00078     const
00079 {
00080     return pollCheck(fd(), true,
00081                      (timeout==-1?-1:senf::ClockService::in_milliseconds(timeout)) );
00082 }
00083 
00084 prefix_ bool senf::FileBody::writeable()
00085     const
00086 {
00087     return pollCheck(fd(),false,0);
00088 }
00089 
00090 prefix_ bool senf::FileBody::waitWriteable(senf::ClockService::clock_type timeout)
00091     const
00092 {
00093     return pollCheck(fd(), false,
00094                      (timeout==-1?-1:senf::ClockService::in_milliseconds(timeout)) );
00095 }
00096 
00097 prefix_ bool senf::FileBody::oobReadable()
00098     const
00099 {
00100     return pollCheck(fd(),true,0,true);
00101 }
00102 
00103 prefix_ bool senf::FileBody::waitOOBReadable(senf::ClockService::clock_type timeout)
00104     const
00105 {
00106     return pollCheck(fd(), true,
00107                      (timeout==-1?-1:senf::ClockService::in_milliseconds(timeout)), true);
00108 }
00109 
00110 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00111 // senf::FileHandle
00112 
00113 prefix_ senf::FileBody & senf::FileHandle::body()
00114 {
00115     SENF_ASSERT(body_, "dereferencing in-valid() FileHandle");
00116     return *body_;
00117 }
00118 
00119 prefix_ senf::FileBody const & senf::FileHandle::body()
00120     const
00121 {
00122     SENF_ASSERT(body_, "dereferencing in-valid() FileHandle");
00123     return *body_;
00124 }
00125 
00126 prefix_ void senf::FileHandle::close()
00127 {
00128     body().close();
00129 }
00130 
00131 prefix_ void senf::FileHandle::terminate()
00132 {
00133     body().terminate();
00134 }
00135 
00136 prefix_ bool senf::FileHandle::readable()
00137     const
00138 {
00139     return body().readable();
00140 }
00141 
00142 prefix_ bool senf::FileHandle::waitReadable(senf::ClockService::clock_type timeout)
00143     const
00144 {
00145     return body().waitReadable(timeout);
00146 }
00147 
00148 prefix_ bool senf::FileHandle::writeable()
00149     const
00150 {
00151     return body().writeable();
00152 }
00153 
00154 prefix_ bool senf::FileHandle::waitWriteable(senf::ClockService::clock_type timeout)
00155     const
00156 {
00157     return body().waitWriteable(timeout);
00158 }
00159 
00160 prefix_ bool senf::FileHandle::oobReadable()
00161     const
00162 {
00163     return body().oobReadable();
00164 }
00165 
00166 prefix_ bool senf::FileHandle::waitOOBReadable(senf::ClockService::clock_type timeout)
00167     const
00168 {
00169     return body().waitOOBReadable(timeout);
00170 }
00171 
00172 prefix_ bool senf::FileHandle::blocking()
00173     const
00174 {
00175     return body().blocking();
00176 }
00177 
00178 prefix_ void senf::FileHandle::blocking(bool status)
00179 {
00180     body().blocking(status);
00181 }
00182 
00183 prefix_ bool senf::FileHandle::eof()
00184     const
00185 {
00186     return body().eof();
00187 }
00188 
00189 prefix_ bool senf::FileHandle::valid()
00190     const
00191 {
00192     return body_ && body().valid();
00193 }
00194 
00195 prefix_ bool senf::FileHandle::boolean_test()
00196     const
00197 {
00198     return valid() && !eof();
00199 }
00200 
00201 prefix_ int senf::FileHandle::fd()
00202     const
00203 {
00204     return body().fd();
00205 }
00206 
00207 prefix_ senf::FileHandle::FileHandle()
00208     : body_(0)
00209 {}
00210 
00211 prefix_ senf::FileHandle::~FileHandle()
00212 {
00213     if (body_ && ! body().is_shared())
00214         body().destroyClose();
00215 }
00216 
00217 prefix_  senf::FileHandle::FileHandle(std::auto_ptr<FileBody> body)
00218     : body_(body.release())
00219 {}
00220 
00221 prefix_ senf::FileHandle::FileHandle(FileBody::ptr body)
00222     : body_(body)
00223 {}
00224 
00225 prefix_ senf::FileBody & senf::FileHandle::body(FileHandle & handle)
00226 {
00227     return handle.body();
00228 }
00229 
00230 prefix_ senf::FileBody const & senf::FileHandle::body(FileHandle const & handle)
00231 {
00232     return handle.body();
00233 }
00234 
00235 prefix_ void senf::FileHandle::fd(int fd)
00236 {
00237     body().fd(fd);
00238 }
00239 
00240 prefix_ senf::FileHandle senf::FileHandle::cast_static(FileHandle handle)
00241 {
00242     return handle;
00243 }
00244 
00245 prefix_ senf::FileHandle senf::FileHandle::cast_dynamic(FileHandle handle)
00246 {
00247     return handle;
00248 }
00249 
00250 prefix_ int senf::retrieve_filehandle(FileHandle handle)
00251 {
00252     return handle.fd();
00253 }
00254 
00255 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00256 #undef prefix_
00257 
00258 
00259 // Local Variables:
00260 // mode: c++
00261 // fill-column: 100
00262 // c-file-style: "senf"
00263 // indent-tabs-mode: nil
00264 // ispell-local-dictionary: "american"
00265 // compile-command: "scons -u test"
00266 // comment-column: 40
00267 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research