X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Socket%2FFileHandle.cci;h=e04980a3ac4081bba7478ecd5981f782d560dcd6;hb=3c3f12e715cd474208351347316f59fdaf19ef81;hp=62cbfaf5881abd6fa517ceadeef2f01f8570a449;hpb=1ad3873b372da6187b1fbc645bf276287d2efb54;p=senf.git diff --git a/Socket/FileHandle.cci b/Socket/FileHandle.cci index 62cbfaf..e04980a 100644 --- a/Socket/FileHandle.cci +++ b/Socket/FileHandle.cci @@ -1,9 +1,9 @@ // $Id$ // // Copyright (C) 2006 -// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) -// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) -// Stefan Bund +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Stefan Bund // // 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 @@ -27,6 +27,7 @@ //#include "FileHandle.ih" // Custom includes +#include "../Utils/senfassert.hh" #include #include "../Utils/Exception.hh" @@ -40,33 +41,6 @@ prefix_ senf::FileBody::FileBody(int fd) : fd_(fd) {} -prefix_ senf::FileBody::~FileBody() -{ - if (valid()) - try { - close(); - } - catch (...) { - terminate(); - } -} - -prefix_ void senf::FileBody::close() -{ - if (!valid()) - throwErrno(EBADF); - v_close(); - fd_ = -1; -} - -prefix_ void senf::FileBody::terminate() -{ - if (valid()) { - v_terminate(); - fd_ = -1; - } -} - prefix_ senf::FileHandle senf::FileBody::handle() { return FileHandle(ptr(this)); @@ -122,6 +96,19 @@ prefix_ void senf::FileBody::waitWriteable() /////////////////////////////////////////////////////////////////////////// // 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(); @@ -195,6 +182,12 @@ prefix_ senf::FileHandle::FileHandle() : body_(0) {} +prefix_ senf::FileHandle::~FileHandle() +{ + if (body_ && ! body().is_shared()) + body().destroyClose(); +} + prefix_ senf::FileHandle::FileHandle(std::auto_ptr body) : body_(body.release()) {} @@ -203,19 +196,6 @@ prefix_ senf::FileHandle::FileHandle(FileBody::ptr body) : body_(body) {} -prefix_ senf::FileBody & senf::FileHandle::body() -{ - BOOST_ASSERT(body_); - return *body_; -} - -prefix_ senf::FileBody const & senf::FileHandle::body() - const -{ - BOOST_ASSERT(body_); - return *body_; -} - prefix_ senf::FileBody & senf::FileHandle::body(FileHandle & handle) { return handle.body();