X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Socket%2FFileHandle.cc;h=bc8ea9caf21923dd77cdb2897f91116240ca2fe6;hb=3863d46dd898b7bc35ea8c6ccd8563b18762a6b6;hp=687bde711b4c82d9a5e0069f0a7368e45f12a624;hpb=ac6a813d9d99f7add4e13aff7a4bcd314d5604a6;p=senf.git diff --git a/Socket/FileHandle.cc b/Socket/FileHandle.cc index 687bde7..bc8ea9c 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 +// Copyright (C) 2006 +// 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 @@ -20,7 +20,9 @@ // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// Definition of non-inline non-template functions +/** \file + \brief FileHandle non-inline non-template implementation + */ #include "FileHandle.hh" //#include "FileHandle.ih" @@ -31,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() @@ -63,45 +95,56 @@ 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(""); } -prefix_ bool senf::FileBody::pollCheck(int fd, bool incoming, bool block) +/* We don't take POLLIN/POLLOUT as argument to avoid having to include + sys/poll.h in the .cci file (and therefore indirectly into the .hh + and then every file which uses FileHandle) */ +prefix_ bool senf::FileBody::pollCheck(int fd, bool incoming, int timeout, bool oob) const { struct ::pollfd pfd; ::memset(&pfd,0,sizeof(pfd)); pfd.fd = fd; - pfd.events = incoming?POLLIN:POLLOUT; + pfd.events = incoming?(oob?POLLPRI:POLLIN):POLLOUT; int rv = -1; do { - rv = ::poll(&pfd,1,block?-1:0); + rv = ::poll(&pfd,1,timeout); if (rv<0) switch (errno) { case EINTR: break; default: - throw SystemException(errno); + SENF_THROW_SYSTEM_EXCEPTION(""); } } while (rv<0); return rv>0; } +prefix_ senf::FileBody::~FileBody() +{} + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ // 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: