X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Socket%2FFileHandle.ih;h=b13f2feac59ebd4913ed69055232388e8c8128cd;hb=532240d72e09e19e57fac9bb55c2560b9c9e5b97;hp=24c05283c9abc66c67f1f5fc85d4e5dea757e6a9;hpb=70256cc93f59f5d2c9b3428775a181e5e225bfc5;p=senf.git diff --git a/Socket/FileHandle.ih b/Socket/FileHandle.ih index 24c0528..b13f2fe 100644 --- a/Socket/FileHandle.ih +++ b/Socket/FileHandle.ih @@ -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 @@ -21,114 +21,128 @@ // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /** \file - \brief senf::FileHandle internal header + \brief FileHandle internal header */ -#ifndef IH_FileHandle_ -#define IH_FileHandle_ 1 +#ifndef IH_SENF_Socket_FileHandle_ +#define IH_SENF_Socket_FileHandle_ 1 // Custom includes #include -#include "Utils/intrusive_refcount.hh" +#include "../Utils/intrusive_refcount.hh" +#include "../Utils/pool_alloc_mixin.hh" ///////////////////////////////ih.p//////////////////////////////////////// namespace senf { + class FileHandle; - /** \brief senf::FileHandle referenced body - - \internal + /** \brief FileHandle referenced body - The senf::FileBody class formes the body part of the handle/body structure of the FileHandle - interface. It manages the FileHandle data and is referenced by senf::FileHandle. It is - automatically managed using reference counting. + \internal - Since the senf::FileHandle class forwards most calls directly to the underlying - senf::FileBody instance, most members are documented in senf::FileHandle. + The senf::FileBody class forms the body part of the handle/body structure of the FileHandle + interface. It manages the FileHandle data and is referenced by senf::FileHandle. It is + automatically managed using reference counting. - \section filebody_new Writing senf::FileBody derived classes + Since the senf::FileHandle class forwards most calls directly to the underlying + senf::FileBody instance, most members are documented in senf::FileHandle. - It is possible to write customized senf::FileBody derived body implementations. This - implementation can then be used be a senf::FileHandle derived class to customize the - FileHandle behavior. Handling the body directly by the handle class ensures, that no invalid - handles can be created (a senf::FileHandle derived handle expecting a specific body type but - pointing to a different body type). + \section filebody_new Writing senf::FileBody derived classes - To customize the behavior, a virtual interface is provided. This interface only covers some - basic funcionality which is only used infrequently during the lifetime of a FileHandle - instance. + It is possible to write customized senf::FileBody derived body implementations. This + implementation can then be used be a senf::FileHandle derived class to customize the + FileHandle behavior. Handling the body directly by the handle class ensures, that no invalid + handles can be created (a senf::FileHandle derived handle expecting a specific body type but + pointing to a different body type). + To customize the behavior, a virtual interface is provided. This interface only covers some + basic functionality which is only used infrequently during the lifetime of a FileHandle + instance. + + \attention Whenever a new class is derived from FileBody which adds new members, this class + \e must also derive from senf::pool_alloc_mixin */ class FileBody - : public senf::intrusive_refcount + : public senf::intrusive_refcount, + public senf::pool_alloc_mixin { public: /////////////////////////////////////////////////////////////////////////// // Types - + typedef boost::intrusive_ptr ptr; /////////////////////////////////////////////////////////////////////////// ///\name Structors and default members ///@{ - - explicit FileBody(int fd=-1); ///< Create new instance - /**< You need to pass a real file descriptor to this - constructor not some arbitrary id even if you overload - all the virtual members. If the file descriptor is -1 the - resulting body/handle is not valid() */ + + explicit FileBody(int fd=-1); ///< Create new instance + /**< You need to pass a real file descriptor to this + constructor not some arbitrary id even if you overload + all the virtual members. If the file descriptor is -1 the + resulting body/handle is not valid() */ virtual ~FileBody(); + // NO DESTRUCTOR HERE (that is, only an empty virtual destructor) - destructors and virtual + // functions don't mix. What would be in the the destructor is in 'destroyClose()' which is + // called from FileHandle::~FileHandle() *before* the last handle dies. + // no copy // no conversion constructors ///@} /////////////////////////////////////////////////////////////////////////// + FileHandle handle(); + int fd() const; void fd(int fd); void close(); void terminate(); + void destroyClose(); bool readable() const; - void waitReadable() const; + bool waitReadable(senf::ClockService::clock_type timeout) const; bool writeable() const; - void waitWriteable() const; + bool waitWriteable(senf::ClockService::clock_type timeout) const; + bool oobReadable() const; + bool waitOOBReadable(senf::ClockService::clock_type timeout) const; bool blocking() const; void blocking(bool status); bool eof() const; bool valid() const; - + private: /////////////////////////////////////////////////////////////////////////// // Virtual interface for subclasses to override - virtual void v_close(); ///< Called to close the file descriptor - /**< You should probably always call the global ::close() - function in this member, however you might want to do - some additional cleanup here. If the operation fails, you - are allowed to throw (preferably a - senf::SystemException). - - \throws senf::SystemException */ - virtual void v_terminate(); ///< Called to forcibly close the file descriptor - /**< This member is called by the destructor (and by - terminate()) to close the descriptor. This member must \e - never throw, it should probably just ignore error - conditions (there's not much else you can do) */ - virtual bool v_eof() const; ///< Called by eof() - virtual bool v_valid() const; ///< Called by valid() - /**< This member is only called, if the file descriptor is - not -1 */ + virtual void v_close(); ///< Called to close the file descriptor + /**< You should probably always call the global ::close() + function in this member, however you might want to do + some additional cleanup here. If the operation fails, you + are allowed to throw (preferably a + senf::SystemException). + + \throws senf::SystemException */ + virtual void v_terminate(); ///< Called to forcibly close the file descriptor + /**< This member is called by the destructor (and by + terminate()) to close the descriptor. This member must \e + never throw, it should probably just ignore error + conditions (there's not much else you can do) */ + virtual bool v_eof() const; ///< Called by eof() + virtual bool v_valid() const; ///< Called by valid() + /**< This member is only called, if the file descriptor is + not -1 */ protected: - + private: - bool pollCheck(int fd, bool incoming, bool block=false) const; + bool pollCheck(int fd, bool incoming, int timeout, bool oob=false) const; int fd_; }; @@ -141,6 +155,10 @@ namespace senf { // Local Variables: // mode: c++ -// c-file-style: "senf" // fill-column: 100 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// comment-column: 40 // End: