X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Socket%2FFileHandle.cc;h=2b1e176989dc3d6d16d9e266e4e7348811e8a805;hb=3cb0a2ff50b8f1111da34b696e64fb1b037cd683;hp=bdc4eca5a49c8c288bbedca9bf829859f158ad25;hpb=85ab07d100a382467a42e19d741d403a7a96c951;p=senf.git diff --git a/Socket/FileHandle.cc b/Socket/FileHandle.cc index bdc4eca..2b1e176 100644 --- a/Socket/FileHandle.cc +++ b/Socket/FileHandle.cc @@ -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 @@ -33,15 +33,45 @@ #include #include #include -#include "Utils/Exception.hh" +#include "../Utils/Exception.hh" #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////// +// senf::FileBody + +prefix_ void senf::FileBody::close() +{ + if (!valid()) + throw SystemException(EBADF SENF_EXC_DEBUGINFO); + v_close(); + fd_ = -1; +} + +prefix_ void senf::FileBody::terminate() +{ + if (valid()) { + v_terminate(); + fd_ = -1; + } +} + +prefix_ void senf::FileBody::destroyClose() +{ + if (valid()) + try { + close(); + } + catch (...) { + terminate(); + } +} + prefix_ void senf::FileBody::v_close() { if (::close(fd_) != 0) - throw SystemException(errno); + SENF_THROW_SYSTEM_EXCEPTION(""); } prefix_ void senf::FileBody::v_terminate() @@ -65,17 +95,17 @@ prefix_ bool senf::FileBody::blocking() const { int flags = ::fcntl(fd(),F_GETFL); - if (flags < 0) throw SystemException(errno); + if (flags < 0) SENF_THROW_SYSTEM_EXCEPTION(""); return ! (flags & O_NONBLOCK); } prefix_ void senf::FileBody::blocking(bool status) { int flags = ::fcntl(fd(),F_GETFL); - if (flags < 0) throw SystemException(errno); + if (flags < 0) SENF_THROW_SYSTEM_EXCEPTION(""); if (status) flags &= ~O_NONBLOCK; else flags |= O_NONBLOCK; - if (::fcntl(fd(), F_SETFL, flags) < 0) throw SystemException(errno); + if (::fcntl(fd(), F_SETFL, flags) < 0) SENF_THROW_SYSTEM_EXCEPTION(""); } /* We don't take POLLIN/POLLOUT as argument to avoid having to include @@ -96,7 +126,7 @@ prefix_ bool senf::FileBody::pollCheck(int fd, bool incoming, bool block) case EINTR: break; default: - throw SystemException(errno); + SENF_THROW_SYSTEM_EXCEPTION(""); } } while (rv<0); return rv>0; @@ -112,4 +142,6 @@ prefix_ bool senf::FileBody::pollCheck(int fd, bool incoming, bool block) // c-file-style: "senf" // indent-tabs-mode: nil // ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// comment-column: 40 // End: