Socket/Protocols/Raw: EUI64 documentation
[senf.git] / Socket / FileHandle.cci
index bb366ba..6db39f5 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 //
-// Copyright (C) 2006 
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-//     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
+// Copyright (C) 2006
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+//     Stefan Bund <g0dil@berlios.de>
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
 // Free Software Foundation, Inc.,
 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
-// Definition of inline non-template functions
+/** \file
+    \brief FileHandle inline non-template implementation
+ */
 
 //#include "FileHandle.ih"
 
 // Custom includes
+#include "../Utils/senfassert.hh"
 #include <errno.h>
-#include "Utils/Exception.hh"
+#include "../Utils/Exception.hh"
 
 #define prefix_ inline
 ///////////////////////////////cci.p///////////////////////////////////////
 
 ///////////////////////////////////////////////////////////////////////////
-// satcom::lib::FileBody
+// senf::FileBody
 
-prefix_ satcom::lib::FileBody::FileBody(int fd)
+prefix_ senf::FileBody::FileBody(int fd)
     : fd_(fd)
 {}
 
-prefix_  satcom::lib::FileBody::~FileBody()
+prefix_ senf::FileHandle senf::FileBody::handle()
 {
-    if (valid())
-        try {
-            close();
-        }
-        catch (...) {
-            terminate();
-        }
+    return FileHandle(ptr(this));
 }
 
-prefix_ void satcom::lib::FileBody::close()
+prefix_ int senf::FileBody::fd()
+    const
 {
-    if (!valid())
-        throw SystemException(EBADF);
-    v_close();
-    fd_ = -1;
+    return fd_;
 }
 
-prefix_ void satcom::lib::FileBody::terminate()
+prefix_ void senf::FileBody::fd(int fd)
 {
-    if (valid()) {
-        v_terminate();
-        fd_ = -1;
-    }
+    fd_ = fd;
 }
 
-prefix_ int satcom::lib::FileBody::fd()
+prefix_ bool senf::FileBody::eof()
     const
 {
-    return fd_;
+    return v_eof();
 }
 
-prefix_ void satcom::lib::FileBody::fd(int fd)
+prefix_ bool senf::FileBody::valid()
+    const
 {
-    fd_ = fd;
+    return fd_!=-1 && v_valid();
 }
 
-prefix_ bool satcom::lib::FileBody::eof()
+prefix_ bool senf::FileBody::readable()
     const
 {
-    return v_eof();
+    return pollCheck(fd(),true,0);
 }
 
-prefix_ bool satcom::lib::FileBody::valid()
+prefix_ bool senf::FileBody::waitReadable(senf::ClockService::clock_type timeout)
     const
 {
-    return fd_!=-1 && v_valid();
+    return pollCheck(fd(), true, 
+                     (timeout==-1?-1:senf::ClockService::in_milliseconds(timeout)) );
 }
 
-prefix_ bool satcom::lib::FileBody::readable()
+prefix_ bool senf::FileBody::writeable()
     const
 {
-    return pollCheck(fd(),true);
+    return pollCheck(fd(),false,0);
 }
 
-prefix_ void satcom::lib::FileBody::waitReadable()
+prefix_ bool senf::FileBody::waitWriteable(senf::ClockService::clock_type timeout)
     const
 {
-    pollCheck(fd(),true,true);
+    return pollCheck(fd(), false, 
+                     (timeout==-1?-1:senf::ClockService::in_milliseconds(timeout)) );
 }
 
-prefix_ bool satcom::lib::FileBody::writeable()
+prefix_ bool senf::FileBody::oobReadable()
     const
 {
-    return pollCheck(fd(),false);
+    return pollCheck(fd(),true,0,true);
 }
 
-prefix_ void satcom::lib::FileBody::waitWriteable()
+prefix_ bool senf::FileBody::waitOOBReadable(senf::ClockService::clock_type timeout)
     const
 {
-    pollCheck(fd(),false,true);
+    return pollCheck(fd(), true, 
+                     (timeout==-1?-1:senf::ClockService::in_milliseconds(timeout)), true);
 }
 
 ///////////////////////////////////////////////////////////////////////////
-// satcom::lib::FileHandle
+// senf::FileHandle
+
+prefix_ senf::FileBody & senf::FileHandle::body()
+{
+    SENF_ASSERT(body_);
+    return *body_;
+}
+
+prefix_ senf::FileBody const & senf::FileHandle::body()
+    const
+{
+    SENF_ASSERT(body_);
+    return *body_;
+}
 
-prefix_ void satcom::lib::FileHandle::close()
+prefix_ void senf::FileHandle::close()
 {
     body().close();
 }
 
-prefix_ void satcom::lib::FileHandle::terminate()
+prefix_ void senf::FileHandle::terminate()
 {
     body().terminate();
 }
 
-prefix_ bool satcom::lib::FileHandle::readable()
+prefix_ bool senf::FileHandle::readable()
     const
 {
     return body().readable();
 }
 
-prefix_ void satcom::lib::FileHandle::waitReadable()
+prefix_ bool senf::FileHandle::waitReadable(senf::ClockService::clock_type timeout)
     const
 {
-    body().waitReadable();
+    return body().waitReadable(timeout);
 }
 
-prefix_ bool satcom::lib::FileHandle::writeable()
+prefix_ bool senf::FileHandle::writeable()
     const
 {
     return body().writeable();
 }
 
-prefix_ void satcom::lib::FileHandle::waitWriteable()
+prefix_ bool senf::FileHandle::waitWriteable(senf::ClockService::clock_type timeout)
     const
 {
-    body().waitWriteable();
+    return body().waitWriteable(timeout);
 }
 
-prefix_ bool satcom::lib::FileHandle::blocking()
+prefix_ bool senf::FileHandle::oobReadable()
+    const
+{
+    return body().oobReadable();
+}
+
+prefix_ bool senf::FileHandle::waitOOBReadable(senf::ClockService::clock_type timeout)
+    const
+{
+    return body().waitOOBReadable(timeout);
+}
+
+prefix_ bool senf::FileHandle::blocking()
     const
 {
     return body().blocking();
 }
 
-prefix_ void satcom::lib::FileHandle::blocking(bool status)
+prefix_ void senf::FileHandle::blocking(bool status)
 {
     body().blocking(status);
 }
 
-prefix_ bool satcom::lib::FileHandle::eof()
+prefix_ bool senf::FileHandle::eof()
     const
 {
     return body().eof();
 }
 
-prefix_ bool satcom::lib::FileHandle::valid()
+prefix_ bool senf::FileHandle::valid()
     const
 {
-    return body().valid();
+    return body_ && body().valid();
 }
 
-prefix_ bool satcom::lib::FileHandle::boolean_test()
+prefix_ bool senf::FileHandle::boolean_test()
     const
 {
     return valid() && !eof();
 }
 
-prefix_ int satcom::lib::FileHandle::fd()
+prefix_ int senf::FileHandle::fd()
     const
 {
     return body().fd();
 }
 
-prefix_  satcom::lib::FileHandle::FileHandle(std::auto_ptr<FileBody> body)
-    : body_(body.release())
+prefix_ senf::FileHandle::FileHandle()
+    : body_(0)
 {}
 
-prefix_ satcom::lib::FileBody & satcom::lib::FileHandle::body()
+prefix_ senf::FileHandle::~FileHandle()
 {
-    return *body_;
+    if (body_ && ! body().is_shared())
+        body().destroyClose();
 }
 
-prefix_ satcom::lib::FileBody const & satcom::lib::FileHandle::body()
-    const
-{
-    return *body_;
-}
+prefix_  senf::FileHandle::FileHandle(std::auto_ptr<FileBody> body)
+    : body_(body.release())
+{}
+
+prefix_ senf::FileHandle::FileHandle(FileBody::ptr body)
+    : body_(body)
+{}
 
-prefix_ satcom::lib::FileBody & satcom::lib::FileHandle::body(FileHandle & handle)
+prefix_ senf::FileBody & senf::FileHandle::body(FileHandle & handle)
 {
     return handle.body();
 }
 
-prefix_ satcom::lib::FileBody const &
-satcom::lib::FileHandle::body(FileHandle const & handle)
+prefix_ senf::FileBody const &
+senf::FileHandle::body(FileHandle const & handle)
 {
     return handle.body();
 }
 
-prefix_ void satcom::lib::FileHandle::fd(int fd)
+prefix_ void senf::FileHandle::fd(int fd)
 {
     body().fd(fd);
 }
 
-prefix_ satcom::lib::FileHandle::FileHandle
-satcom::lib::FileHandle::cast_static(FileHandle handle)
+prefix_ senf::FileHandle::FileHandle
+senf::FileHandle::cast_static(FileHandle handle)
 {
     return handle;
 }
 
-prefix_ satcom::lib::FileHandle
-satcom::lib::FileHandle::cast_dynamic(FileHandle handle)
+prefix_ senf::FileHandle
+senf::FileHandle::cast_dynamic(FileHandle handle)
 {
     return handle;
 }
 
-prefix_ int satcom::lib::retrieve_filehandle(FileHandle handle)
+prefix_ int senf::retrieve_filehandle(FileHandle handle)
 {
     return handle.fd();
 }
@@ -238,5 +262,10 @@ prefix_ int satcom::lib::retrieve_filehandle(FileHandle handle)
 \f
 // Local Variables:
 // mode: c++
-// c-file-style: "satcom"
+// fill-column: 100
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
 // End: