// $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
//#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///////////////////////////////////////
: fd_(fd)
{}
-prefix_ senf::FileBody::~FileBody()
+prefix_ senf::FileHandle senf::FileBody::handle()
{
- if (valid())
- try {
- close();
- }
- catch (...) {
- terminate();
- }
-}
-
-prefix_ void senf::FileBody::close()
-{
- if (!valid())
- throw SystemException(EBADF);
- v_close();
- fd_ = -1;
-}
-
-prefix_ void senf::FileBody::terminate()
-{
- if (valid()) {
- v_terminate();
- fd_ = -1;
- }
+ return FileHandle(ptr(this));
}
prefix_ int senf::FileBody::fd()
///////////////////////////////////////////////////////////////////////////
// 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 senf::FileHandle::close()
{
body().close();
prefix_ bool senf::FileHandle::valid()
const
{
- return body().valid();
+ return body_ && body().valid();
}
prefix_ bool senf::FileHandle::boolean_test()
return body().fd();
}
-prefix_ senf::FileHandle::FileHandle(std::auto_ptr<FileBody> body)
- : body_(body.release())
+prefix_ senf::FileHandle::FileHandle()
+ : body_(0)
{}
-prefix_ senf::FileBody & senf::FileHandle::body()
+prefix_ senf::FileHandle::~FileHandle()
{
- return *body_;
+ if (body_ && ! body().is_shared())
+ body().destroyClose();
}
-prefix_ senf::FileBody const & senf::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_ senf::FileBody & senf::FileHandle::body(FileHandle & handle)
{
\f
// Local Variables:
// mode: c++
+// fill-column: 100
// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
// End: